Skip to content

Instantly share code, notes, and snippets.

@kkamegawa
Last active February 2, 2023 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkamegawa/6594200b770c0326f249ea797e3b61cd to your computer and use it in GitHub Desktop.
Save kkamegawa/6594200b770c0326f249ea797e3b61cd to your computer and use it in GitHub Desktop.
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