azure - ARM 模板更新覆盖 Azure 函数中的某些内容导致错误“函数运行时无法启动”
问题描述
如果我通过 Azure 门户创建一个 dotnet C# Azure Function Web 应用程序,我可以 (zip) 发布我的函数并且一切似乎都可以正常工作。如果我导航到门户中的函数,我可以看到为我创建的 function.json,并且一切似乎都运行良好。
然后,根据我们的基础架构即代码原则,作为我们在 Azure Dev Ops 中部署管道的一部分,我们执行一个 ARM 模板来更新具有我们从门户中的 Function App 复制的所有设置的 Function App。
在此模板运行后,当我们导航到门户中的函数时,我们会得到:
Error:
The function runtime is unable to start.
Session Id: a3dd6ec59c9a459d947ef1ffbb9bf00b
Timestamp: 2020-01-04T23:31:08.741Z
而且我们没有看到 Function.json。但是,该功能似乎仍在工作(!)。如果我查看 Kudu Host 日志,那么似乎没有任何错误,例如
2020-01-04T23:29:27.639 [Information] Starting JobHost
2020-01-04T23:29:27.641 [Information] Starting Host (HostId=dev-backend, InstanceId=b9a1e02b-faee-4a37-844c-412622583ff7, Version=2.0.12888.0, ProcessId=7440, AppDomainId=1, InDebugMode=True, InDiagnosticMode=False, FunctionsExtensionVersion=~2)
2020-01-04T23:29:27.670 [Information] Loading functions metadata
2020-01-04T23:29:27.699 [Information] 1 functions loaded
2020-01-04T23:29:27.860 [Information] Generating 1 job function(s)
2020-01-04T23:29:27.976 [Information] Found the following functions:
Consumer.Function.ConfigurationUpdated.ExecuteAsync
2020-01-04T23:29:28.097 [Information] Initializing function HTTP routes
No HTTP routes mapped
2020-01-04T23:29:28.105 [Information] Host initialized (449ms)
2020-01-04T23:29:28.459 [Information] Host started (810ms)
2020-01-04T23:29:28.459 [Information] Job host started
2020-01-04T23:29:33.474 [Information] Host lock lease acquired by instance ID 'e4e6f1cb6c07cd9bd67163acfe2dba75'.
我不确定 ARM 模板中可能缺少什么导致它中断,或者在哪里可以找到运行时无法启动的原因......或者即使它真的完全正常工作。
我使用的模板是:
{
"apiVersion": "2018-02-01",
"name": "[variables('statisticsBackendContainer')]",
"type": "Microsoft.Web/sites",
"kind": "functionapp",
"location": "[resourceGroup().location]",
"tags": {
"service": "statistics",
"costCenter": "[parameters('costcentre')]",
"[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', variables('servicePlan'))]": "Resource"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', variables('servicePlan'))]",
"[concat('Microsoft.Sql/servers/', variables('databaseServer'))]",
"[concat('Microsoft.Storage/storageAccounts/', variables('loggingStorageAccount'))]"
],
"properties": {
"name": "[variables('statisticsBackendContainer')]",
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('servicePlan'))]",
"clientAffinityEnabled": false,
"httpsOnly": true,
"hostingEnvironment": "",
"siteConfig": {
"phpVersion": "off",
"Use32BitWorkerProcess": true,
"AlwaysOn": true,
"appSettings": [
{
"name": "AzureWebJobsStorage",
"connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('loggingStorageAccount'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('loggingStorageAccount')), '2016-01-01').keys[0].value)]",
"type": 3
},
{
"name": "AppSettings:apiSecret",
"value": "[variables('apiSecret')]"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~2"
},
{
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
"value": "[reference(concat('microsoft.insights/components/',variables('statisticsBackendContainer')), '2015-05-01').InstrumentationKey]"
}
],
"connectionStrings": [
{
"name": "microsoft.servicebus.connectionstring",
"connectionString": "[listkeys(variables('sendlistenServiceBusNamespace'), '2014-09-01').primaryConnectionString]",
"type": 3
},
{
"name": "statistics.connection",
"connectionString": "[concat('Server=tcp:', reference(concat('Microsoft.Sql/servers/', variables('databaseServer'))).fullyQualifiedDomainName, ',1433;Database=', variables('databaseStatisticsName'), ';User Id=', parameters('appLogin'), '@', variables('serviceNameEnvironment'), ';Password=', parameters('appLoginPassword'), ';Encrypt=True;Connection Timeout=30;')]",
"type": 2
},
{
"name": "logging.connection",
"connectionString": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('loggingStorageAccount'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('loggingStorageAccount')), '2016-01-01').keys[0].value)]",
"type": 3
},
{
"name": "management.webhook",
"connectionString": "[concat('https://',variables('managementApiContainer'),'.azurewebsites.net')]",
"type": 3
}
]
}
}
},
解决方案
最后,我认为 ARM 模板具有误导性,因为已部署的 Function 应用程序中缺少 AzureWebJobsStorage AppSetting。当我确定它在 ARM 模板中并重新部署后,Azure 门户中的一切似乎都正常。
推荐阅读
- azure - 无法从资源组中获取虚拟机列表
- swift - 显示分页结果,同时观察 Realm Swift 中的变化
- reactjs - 无法捕获包含在 deck.gl@^7.1.10 中的 Marker 子级的 onClick 事件
- shell - 远程主机中设置了环境变量。$home=/apps/乐购/app/。我想 ssh 到那个主机并想去 cd $home
- javascript - 数组修改
- doit - 为什么“doit list”在大型数据集上运行数小时?
- kotlin-coroutines - [kotlin]将函数标记为可挂起
- python - 如何使用 paraview 的可编程滤波器进行比较?
- django - 如何在 Django Rest Framework 中的操作中进行分页
- excel - 强力查询递归功能:在递归步骤之后增加更多步骤