使用Bicep部署Python3.11 Azure Functions遇错,求正确模板
解决Azure Functions Python 3.11部署失败的Bicep模板修正方案
部署失败的核心原因是Linux环境的Function App中同时设置了pythonVersion和linuxFxVersion字段,这两个配置冲突。Linux环境下仅需通过linuxFxVersion指定Python版本,同时要保证运行时配置完整,避免后续出现WorkerConfig找不到的错误。
以下是可成功部署Python 3.11版本Azure Functions的Bicep模板:
param location string = resourceGroup().location // 存储账户名称需全局唯一,建议替换为自定义名称 param storageAccountName string = 'samplestorage123' // Function App名称需全局唯一,建议替换为自定义名称 param functionAppName string = 'testfunc' param appServicePlanName string = 'testplan' resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = { name: storageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' properties: { accessTier: 'Hot' } } resource appServicePlan 'Microsoft.Web/serverfarms@2023-01-01' = { name: appServicePlanName location: location kind: 'linux' sku: { name: 'Y1' // Consumption计划 } properties: {} } resource functionApp 'Microsoft.Web/sites@2023-01-01' = { name: functionAppName location: location kind: 'functionapp,linux' properties: { enabled: true serverFarmId: appServicePlan.id reserved: true // Linux环境必须设置为true siteConfig: { appSettings: [ { name: 'FUNCTIONS_EXTENSION_VERSION' value: '~4' // Python 3.11需要Runtime 4.x以上 } { name: 'FUNCTIONS_WORKER_RUNTIME' value: 'python' } { name: 'AzureWebJobsStorage' value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}' } { name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING' value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}' } { name: 'WEBSITE_CONTENTSHARE' value: toLower(functionAppName) // 建议使用Function App名称的小写形式,避免命名问题 } ] cors: { allowedOrigins: [ 'https://portal.azure.com' ] } use32BitWorkerProcess: false ftpsState: 'Disabled' linuxFxVersion: 'Python|3.11' // Linux环境唯一指定Python版本的字段 } clientAffinityEnabled: false publicNetworkAccess: 'Enabled' httpsOnly: true } }
关键修改说明:
- 移除了
siteConfig中的pythonVersion字段:Linux Function App无需该配置,仅通过linuxFxVersion指定运行时版本,两者共存会触发格式验证错误 - 修正内容共享名称:将
WEBSITE_CONTENTSHARE设为Function App名称的小写形式,避免因大小写导致的存储文件共享创建问题 - 保留
reserved: true:Linux Consumption计划必须设置该属性,否则会部署失败 - 确认运行时版本匹配:
FUNCTIONS_EXTENSION_VERSION设为~4,确保与Python 3.11兼容
内容的提问来源于stack exchange,提问作者tekunikaruza
相关产品推荐
相关产品推荐

