我尝试在 ARM 模板中复制以下 Azure CLI 命令。它基于 documentation并且工作正常。
az functionapp create --resource-group AzureFunctionsQuickstart-rg --p myappserviceplan --runtime dotnet-isolated --runtime-version 5.0 --functions-version 3 --name <APP_NAME> --storage-account <STORAGE_NAME> --os-type linux
但是,在执行下面的 ARM 模板时,打开 https://Service unavailable
。如果我使用 AZ 命令,我会看到Your Functions 3.0 应用程序已启动并正在运行
。通过 func azure functionapppublish
或 Azure Pipelines 发布我的函数似乎在大多数情况下也会超时,尤其是使用 Azure Function App 任务的 Azure Pipelines。
我需要改变什么?
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},
"storageAccountName": {
"type": "string",
"metadata": {
"description": "The name of the existing storage account."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for app function"
}
},
"hostingPlanName": {
"type": "string",
"metadata": {
"description": "Name of the existing hosting plan to use."
}
}
},
"variables": {
"functionAppName": "[parameters('appName')]"
},
"resources": [
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Web/sites",
"name": "[variables('functionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp,linux",
"dependsOn": [
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
"siteConfig": {
"alwaysOn": true,
"appSettings": [
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~3"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet-isolated"
}
]
}
}
}
]
}
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: 'functionAppLinux'
appName: '$(functionAppName)'
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
runtimeStack: 'DOTNET-ISOLATED|5.0'
最佳答案
解决方案是在模板中添加一点额外的参数 "linuxFxVersion": "DOTNET-ISOLATED|5.0"
。我过去仅在通过 Azure Pipelines 部署应用程序时才设置此选项,但目前似乎没有此选项也会阻止您的部署。
工作 ARM 模板:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},
"storageAccountName": {
"type": "string",
"metadata": {
"description": "The name of the existing storage account."
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for app function"
}
},
"hostingPlanName": {
"type": "string",
"metadata": {
"description": "Name of the existing hosting plan to use."
}
}
},
"variables": {
"functionAppName": "[parameters('appName')]"
},
"resources": [
{
"apiVersion": "2020-06-01",
"type": "Microsoft.Web/sites",
"name": "[variables('functionAppName')]",
"location": "[parameters('location')]",
"kind": "functionapp,linux",
"dependsOn": [
],
"properties": {
"serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
"siteConfig": {
"alwaysOn": true,
"appSettings": [
{
"name": "AzureWebJobsStorage",
"value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
},
{
"name": "FUNCTIONS_EXTENSION_VERSION",
"value": "~3"
},
{
"name": "FUNCTIONS_WORKER_RUNTIME",
"value": "dotnet-isolated"
}
],
"linuxFxVersion": "DOTNET-ISOLATED|5.0"
}
}
}
]
}
关于azure - 通过ARM模板创建.NET 5 Function App后为"Service Unavailable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66591407/