1

At the moment using the default domain for azure function app. How can I use a custom domain? Is there a parameter for functionApp to do this?

Bicep template to deploy azure function app.

param  name  string = 'Hamid'
param  location  string = 'UK South'
resource  storageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = {
name: name
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
resource  applicationInsights  'Microsoft.Insights/components@2020-02-02' = {
name: 'nameapplication-insights'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
Request_Source: 'rest'
}
}
resource  hostingPlan  'Microsoft.Web/serverfarms@2021-03-01' = {
name: name
location: location
kind: 'Linux'
sku: {
name: 'Y1'
tier: 'Dynamic'
}
properties: {
reserved: true
}
}
resource  functionApp  'Microsoft.Web/sites@2021-03-01' = {
name: name
location: location
kind: 'functionapp'
identity: {
type: 'SystemAssigned'
}
properties: {
serverFarmId: hostingPlan.id
siteConfig: {
pythonVersion: '3.9'
linuxFxVersion: 'python|3.9'
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'SCM_DO_BUILD_DURING_DEPLOYMENT' 
value: 'true'
}
{
name: 'ENABLE_ORYX_BUILD'  
value: 'true'
}
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
value: applicationInsights.properties.InstrumentationKey
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'python'
}
]
}
httpsOnly: true
}
}

........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Hamid
  • 103
  • 9

1 Answers1

1

At the moment using the default domain for azure function app. How can I use a custom domain?

  • I used vs code editor to deploy bicep format file to create function app and add custom domain to it.

  • Installed Bicep extension in vs code

Below is the code which I worked.

param  appName  string
param  location  string
param  storageAccountName  string
param  customDomainName  string
  
resource  storageAccount  'Microsoft.Storage/storageAccounts@2021-06-01' = {
    name: storageAccountName
    location: location
    sku: {
    name: 'Standard_LRS'
}
    kind: 'StorageV2'
}
  
resource  appServicePlan  'Microsoft.Web/serverfarms@2021-03-01' = {
    name: '${appName}-plan'
    location: location
    sku: {
    name: 'Y1'
    tier: 'Dynamic'
    }
    kind: 'functionapp'
        properties: {
        reserved: true
    }
}
  
resource  functionApp  'Microsoft.Web/sites@2021-03-01' = {
    name: appName
    location: location
    kind: 'functionapp'
    properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
        appSettings: [
        {
            name: 'AzureWebJobsStorage'
            value: storageAccount.properties.primaryEndpoints.blob
        }
    ]
            use32BitWorkerProcess: true
        }
    }
}
  
resource  functionAppConfig  'Microsoft.Web/sites/config@2021-02-01' = {
    name: '${functionApp.name}/web'
    properties: {
    numberOfWorkers: 1
    hostNames: [
        '${functionApp.properties.defaultHostName}'
        '${customDomainName}'
    ]
}
dependsOn: [
        functionApp
    ]
}
  
resource  appCustomDomain  'Microsoft.Web/sites/hostNameBindings@2021-03-01' = {
    name: '${functionApp.name}/${customDomainName}'
    properties: {
    azureResourceName: functionApp.id
    azureResourceType: 'Microsoft.Web/sites'
    customHostNameDnsRecordType: 'CName'
    domainId: functionAppConfig.id
    sslState: 'Disabled'
    }
}
  
output  functionAppUrl  string = functionApp.properties.defaultHostName

enter image description here

enter image description here

  • Check the custom domain which newly added to the function app.
  • Navigate to: Function App->Settings->Custom domains

enter image description here

enter image description here

Bhavani
  • 1,725
  • 1
  • 3
  • 6
Suresh Chikkam
  • 623
  • 2
  • 2
  • 6