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

标签 azure azure-functions azure-resource-manager

我尝试在 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 应用程序已启动并正在运行。通过 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/

相关文章:

c# - 当 Azure 计时器函数的执行持续时间长于触发周期时会发生什么情况?

windows - 将参数传递到 Azure ARM 模板

azure - Azure 中的事件日志警报

azure - 我们可以在 ARM 模板部署期间运行休息调用,就像 Azure 对应用服务域所做的那样吗?

database - 根据暂存或生产切换 Azure ConnectionString

azure - Azure ML 中的 "ImportError: No module named seaborn"

javascript - Azure Function - js - 运行不正确,但日志中没有错误

Azure函数: access a folder structure

Azure 角色 - 应用程序启动任务失败,退出代码为 1

Azure SQL DB查找所有数据库中的所有表