"Service Unavailable" 通过 ARM 模板创建 .NET 5 Function App 后

"Service Unavailable" after creating .NET 5 Function App via ARM template

我尝试在 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://.azurewebsites.net得到的是Service unavailable。如果我使用 AZ 命令,我会看到 Your Functions 3.0 app is up and running。通过 func azure functionapp publish 或 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"
        }
      }
    }
  ]
}