@@ -27,6 +27,8 @@ var package_container_name = 'packages'
27
27
// Create a container for the Python code
28
28
var python_container_name = 'python'
29
29
30
+ var storage_connection_string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount .name };EndpointSuffix=${environment ().suffixes .storage };AccountKey=${storageAccount .listKeys ().keys [0 ].value }'
31
+
30
32
// The version of Python to run with
31
33
var python_version = '3.11'
32
34
@@ -50,7 +52,7 @@ resource packageContainer 'Microsoft.Storage/storageAccounts/blobServices/contai
50
52
parent : defBlobServices
51
53
name : package_container_name
52
54
}
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 = {
54
56
parent : defBlobServices
55
57
name : python_container_name
56
58
}
@@ -65,12 +67,14 @@ resource storageBlobDataContributorRoleAssignment 'Microsoft.Authorization/roleA
65
67
}
66
68
67
69
// 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
68
72
resource hostingPlan 'Microsoft.Web/serverfarms@2024-11-01' = {
69
73
name : hostingPlanName
70
74
location : location
71
75
sku : {
72
- name : 'Y1 '
73
- tier : 'Dynamic '
76
+ name : 'FC1 '
77
+ tier : 'FlexConsumption '
74
78
}
75
79
properties : {
76
80
reserved : true
@@ -90,18 +94,10 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
90
94
91
95
// Construct the app settings
92
96
var common_settings = [
93
- {
94
- name : 'FUNCTIONS_EXTENSION_VERSION'
95
- value : '~4'
96
- }
97
97
{
98
98
name : 'APPINSIGHTS_INSTRUMENTATIONKEY'
99
99
value : applicationInsights .properties .InstrumentationKey
100
100
}
101
- {
102
- name : 'FUNCTIONS_WORKER_RUNTIME'
103
- value : 'python'
104
- }
105
101
// Pass the blob container name to the function app - this is the
106
102
// container which is monitored for new packages.
107
103
{
@@ -114,32 +110,56 @@ var common_settings = [
114
110
var app_settings = use_shared_keys ? concat (common_settings , [
115
111
{
116
112
name : 'AzureWebJobsStorage'
117
- value : 'DefaultEndpointsProtocol=https;AccountName=${ storageAccount . name };EndpointSuffix=${ environment (). suffixes . storage };AccountKey=${ storageAccount . listKeys (). keys [ 0 ]. value }'
113
+ value : storage_connection_string
118
114
}
119
115
{
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
126
118
}
127
119
]) : concat (common_settings , [
128
120
{
129
121
name : 'AzureWebJobsStorage__accountName'
130
122
value : storageAccount .name
131
123
}
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.
137
124
{
138
125
name : 'BLOB_CONTAINER_URL'
139
126
value : 'https://${storageAccount .name }.blob.${environment ().suffixes .storage }/${packageContainer .name }/'
140
127
}
141
128
])
142
129
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
+
143
163
// Create the function app.
144
164
resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
145
165
name : functionAppName
@@ -152,13 +172,12 @@ resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
152
172
properties : {
153
173
serverFarmId : hostingPlan .id
154
174
siteConfig : {
155
- linuxFxVersion : 'Python|${python_version }'
156
- pythonVersion : python_version
157
175
appSettings : app_settings
158
176
ftpsState : 'FtpsOnly'
159
177
minTlsVersion : '1.2'
160
178
}
161
179
httpsOnly : true
180
+ functionAppConfig : function_app_config
162
181
}
163
182
}
164
183
0 commit comments