Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure Functions Python Runtime stack sample for bicep
// The following will create an Azure Function app on
// a consumption plan, along with a storage account
param location string = resourceGroup().location
param appNamePrefix string = uniqueString(resourceGroup().id)
var functionAppName = '${appNamePrefix}-functionapp'
var appServiceName = '${appNamePrefix}-appservice'
// remove dashes for storage account name
var storageAccountName = format('{0}sta', replace(appNamePrefix, '-', ''))
var appTags = {
AppID: 'myfunc'
AppName: 'My Function App'
}
// Storage Account
resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
tier: 'Standard'
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
accessTier: 'Hot'
}
tags: appTags
}
// Blob Services for Storage Account
resource blobServices 'Microsoft.Storage/storageAccounts/blobServices@2019-06-01' = {
parent: storageAccount
name: 'default'
properties: {
cors: {
corsRules: []
}
deleteRetentionPolicy: {
enabled: true
days: 7
}
}
}
resource appService 'Microsoft.Web/serverfarms@2020-06-01' = {
name: appServiceName
properties:{
reserved: true
}
location: location
kind: 'linux'
sku: {
name: 'Y1'
tier: 'Dynamic'
}
}
// Function App
resource functionApp 'Microsoft.Web/sites@2020-06-01' = {
name: functionAppName
location: location
identity: {
type: 'SystemAssigned'
}
kind: 'functionapp'
properties: {
httpsOnly: true
serverFarmId: appService.id
clientAffinityEnabled: true
siteConfig: {
pythonVersion: '3.8'
appSettings: [
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}'
}
{
'name': 'FUNCTIONS_EXTENSION_VERSION'
'value': '~3'
}
{
'name': 'FUNCTIONS_WORKER_RUNTIME'
'value': 'python'
}
{
name: 'WEBSITE_CONTENTSHARE'
value: '${toLower(functionAppName)}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}'
}
]
}
}
dependsOn: [
appService
]
}
// Function App Binding
resource functionAppBinding 'Microsoft.Web/sites/hostNameBindings@2020-06-01' = {
parent: functionApp
name: '${functionApp.name}.azurewebsites.net'
properties: {
siteName: functionApp.name
hostNameType: 'Verified'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment