@@ -27,6 +27,8 @@ var package_container_name = 'packages'
2727// Create a container for the Python code
2828var python_container_name = 'python'
2929
30+ var storage_connection_string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount .name };EndpointSuffix=${environment ().suffixes .storage };AccountKey=${storageAccount .listKeys ().keys [0 ].value }'
31+
3032// The version of Python to run with
3133var python_version = '3.11'
3234
@@ -50,7 +52,7 @@ resource packageContainer 'Microsoft.Storage/storageAccounts/blobServices/contai
5052 parent : defBlobServices
5153 name : package_container_name
5254}
53- resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' existing = if (! use_shared_keys ) {
55+ resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' existing = {
5456 parent : defBlobServices
5557 name : python_container_name
5658}
@@ -65,12 +67,14 @@ resource storageBlobDataContributorRoleAssignment 'Microsoft.Authorization/roleA
6567}
6668
6769// Create a hosting plan for the function app
70+ // Using Flex Consumption plan for serverless hosting with enhanced features
71+ // Reference: https://learn.microsoft.com/en-us/azure/azure-functions/flex-consumption-plan
6872resource hostingPlan 'Microsoft.Web/serverfarms@2024-11-01' = {
6973 name : hostingPlanName
7074 location : location
7175 sku : {
72- name : 'Y1 '
73- tier : 'Dynamic '
76+ name : 'FC1 '
77+ tier : 'FlexConsumption '
7478 }
7579 properties : {
7680 reserved : true
@@ -90,18 +94,10 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
9094
9195// Construct the app settings
9296var common_settings = [
93- {
94- name : 'FUNCTIONS_EXTENSION_VERSION'
95- value : '~4'
96- }
9797 {
9898 name : 'APPINSIGHTS_INSTRUMENTATIONKEY'
9999 value : applicationInsights .properties .InstrumentationKey
100100 }
101- {
102- name : 'FUNCTIONS_WORKER_RUNTIME'
103- value : 'python'
104- }
105101 // Pass the blob container name to the function app - this is the
106102 // container which is monitored for new packages.
107103 {
@@ -114,32 +110,56 @@ var common_settings = [
114110var app_settings = use_shared_keys ? concat (common_settings , [
115111 {
116112 name : 'AzureWebJobsStorage'
117- value : 'DefaultEndpointsProtocol=https;AccountName=${ storageAccount . name };EndpointSuffix=${ environment (). suffixes . storage };AccountKey=${ storageAccount . listKeys (). keys [ 0 ]. value }'
113+ value : storage_connection_string
118114 }
119115 {
120- name : 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
121- value : 'DefaultEndpointsProtocol=https;AccountName=${storageAccount .name };EndpointSuffix=${environment ().suffixes .storage };AccountKey=${storageAccount .listKeys ().keys [0 ].value }'
122- }
123- {
124- name : 'WEBSITE_CONTENTSHARE'
125- value : toLower (functionAppName )
116+ name : 'DEPLOYMENT_STORAGE_CONNECTION_STRING'
117+ value : storage_connection_string
126118 }
127119]) : concat (common_settings , [
128120 {
129121 name : 'AzureWebJobsStorage__accountName'
130122 value : storageAccount .name
131123 }
132- {
133- name : 'WEBSITE_RUN_FROM_PACKAGE'
134- value : 'https://${storageAccount .name }.blob.${environment ().suffixes .storage }/${pythonContainer .name }/function_app.zip'
135- }
136- // Pass the container URL to the function app for the `from_container_url` call.
137124 {
138125 name : 'BLOB_CONTAINER_URL'
139126 value : 'https://${storageAccount .name }.blob.${environment ().suffixes .storage }/${packageContainer .name }/'
140127 }
141128])
142129
130+ var function_runtime = {
131+ name : 'python'
132+ version : python_version
133+ }
134+
135+ var deployment_storage_value = 'https://${storageAccount .name }.blob.${environment ().suffixes .storage }/${pythonContainer .name }'
136+
137+ var deployment_authentication = use_shared_keys ? {
138+ type : 'StorageAccountConnectionString'
139+ storageAccountConnectionStringName : 'DEPLOYMENT_STORAGE_CONNECTION_STRING'
140+ } : {
141+ type : 'SystemAssignedIdentity'
142+ }
143+
144+ var flex_deployment_configuration = {
145+ storage : {
146+ type : 'blobContainer'
147+ value : deployment_storage_value
148+ authentication : deployment_authentication
149+ }
150+ }
151+
152+ var flex_scale_and_concurrency = {
153+ maximumInstanceCount : 100
154+ instanceMemoryMB : 2048
155+ }
156+
157+ var function_app_config = {
158+ runtime : function_runtime
159+ scaleAndConcurrency : flex_scale_and_concurrency
160+ deployment : flex_deployment_configuration
161+ }
162+
143163// Create the function app.
144164resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
145165 name : functionAppName
@@ -152,13 +172,12 @@ resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
152172 properties : {
153173 serverFarmId : hostingPlan .id
154174 siteConfig : {
155- linuxFxVersion : 'Python|${python_version }'
156- pythonVersion : python_version
157175 appSettings : app_settings
158176 ftpsState : 'FtpsOnly'
159177 minTlsVersion : '1.2'
160178 }
161179 httpsOnly : true
180+ functionAppConfig : function_app_config
162181 }
163182}
164183
0 commit comments