【问题标题】:Azure Function - "Encountered an error (InternalServerError) from host runtimeAzure 函数 - \"遇到来自主机运行时的错误 (InternalServerError)
【发布时间】:2023-01-19 16:41:49
【问题描述】:

部署 ARM 时,其中:部署了具有 2 个功能的 App Service Plan、Storage、Function 应用程序。部署 2 个函数时出现错误:

{
"status": "Failed",
"error": {
    "code": "BadRequest",
    "message": "Encountered an error (InternalServerError) from host runtime.",
    "details": [
        {
            "message": "Encountered an error (InternalServerError) from host runtime."
        },
        {
            "code": "BadRequest"
        },
        {}
    ]
}

我不知道我还能调试多少以及错误可能出在哪里。

{
        "type": "Microsoft.Web/sites/functions",
        "name": "[concat(parameters('functionApp'),'/',parameters('project'),'-http-',parameters('environment'))]",
        "apiVersion": "2018-11-01",
        "location": "[resourceGroup().location]",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
        ],
        "properties": {
            "name": "[concat(parameters('functionApp'),'/',parameters('project'),'-http-',parameters('environment'))]",
            "scriptFile": "[concat('site/wwwroot/httpTrigger/run.ps1')]",
            "route": "api/{req?}",
            "methods": [
                "GET",
                "POST"
            ],
            "authLevel": "anonymous",
            "direction": "in"
        }
    },
    {
        "type": "Microsoft.Web/sites/functions",
        "name": "[concat(parameters('functionApp'),'/',parameters('project'),'-timerTrigger-',parameters('environment'))]",
        "apiVersion": "2018-11-01",
        "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('functionApp'))]"
        ],
        "properties": {
            "name": "[concat(parameters('functionApp'),'/',parameters('project'),'-timer-',parameters('environment'))]",
            "scriptFile": "[concat('site/wwwroot/timer/run.ps1')]",
            "timeout": "30",
            "bindings": [
                {
                    "name": "myTimer",
                    "type": "timerTrigger",
                    "direction": "in",
                    "schedule": ""
                }
            ]
        }
    }

日志中到处都有相同的错误,

【问题讨论】:

    标签: azure azure-functions azure-resource-manager


    【解决方案1】:
    • 我使用下面的 arm 模板部署了具有两个功能的应用程序服务计划、存储、功能应用程序。
    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
            "sites_fn_3sjvfqv5e3qmc_name": {
                "defaultValue": "fn-3sjvfqv5e3qmc",
          "type": "String"
            },
        "serverfarms_FunctionPlan_name": {
                "defaultValue": "FunctionPlan",
          "type": "String"
        },
        "components_AppInsights_name": {
                "defaultValue": "AppInsights",
          "type": "String"
        },
        "vaults_key_3sjvfqv5e3qmc_name": {
                "defaultValue": "key-3sjvfqv5e3qmc",
          "type": "String"
        },
        "storageAccounts_fnstor3sjvfqv5e3qmc_name": {
                "defaultValue": "fnstor3sjvfqv5e3qmc",
          "type": "String"
        }
        },
      "variables": { },
      "resources": [
        {
            "type": "microsoft.insights/components",
          "apiVersion": "2020-02-02",
          "name": "[parameters('components_AppInsights_name')]",
          "location": "westus2",
          "kind": "web",
          "properties": {
                "Application_Type": "web",
            "RetentionInDays": 90,
            "IngestionMode": "ApplicationInsights",
            "publicNetworkAccessForIngestion": "Enabled",
            "publicNetworkAccessForQuery": "Enabled"
          }
        },
        {
            "type": "Microsoft.KeyVault/vaults",
          "apiVersion": "2022-07-01",
          "name": "[parameters('vaults_key_3sjvfqv5e3qmc_name')]",
          "location": "westus2",
          "properties": {
                "sku": {
                    "family": "A",
              "name": "Standard"
                },
            "tenantId": "<TenantID>",
            "accessPolicies": [],
            "enabledForDeployment": false,
            "enableSoftDelete": true,
            "vaultUri": "[concat('https://', parameters('vaults_key_3sjvfqv5e3qmc_name'), '.vault.azure.net/')]",
            "provisioningState": "Succeeded",
            "publicNetworkAccess": "Enabled"
          }
        },
        {
            "type": "Microsoft.Storage/storageAccounts",
          "apiVersion": "2022-05-01",
          "name": "[parameters('storageAccounts_fnstor3sjvfqv5e3qmc_name')]",
          "location": "westus2",
          "sku": {
                "name": "Standard_LRS",
            "tier": "Standard"
          },
          "kind": "StorageV2",
          "properties": {
                "minimumTlsVersion": "TLS1_0",
            "allowBlobPublicAccess": true,
            "networkAcls": {
                    "bypass": "AzureServices",
              "virtualNetworkRules": [],
              "ipRules": [],
              "defaultAction": "Allow"
            },
            "supportsHttpsTrafficOnly": true,
            "encryption": {
                    "services": {
                        "file": {
                            "keyType": "Account",
                  "enabled": true
                        },
                "blob": {
                            "keyType": "Account",
                  "enabled": true
                }
                    },
              "keySource": "Microsoft.Storage"
            },
            "accessTier": "Hot"
          }
        },
        {
            "type": "Microsoft.Web/serverfarms",
          "apiVersion": "2022-03-01",
          "name": "[parameters('serverfarms_FunctionPlan_name')]",
          "location": "West US 2",
          "sku": {
                "name": "Y1",
            "tier": "Dynamic",
            "size": "Y1",
            "family": "Y",
            "capacity": 0
          },
          "kind": "functionapp",
          "properties": {}
        },
        {
            "type": "Microsoft.Web/sites",
          "apiVersion": "2022-03-01",
          "name": "[parameters('sites_fn_3sjvfqv5e3qmc_name')]",
          "location": "West US 2",
          "dependsOn": [
            "[resourceId('Microsoft.Web/serverfarms', parameters('serverfarms_FunctionPlan_name'))]"
          ],
          "kind": "functionapp",
          "properties": {
                "enabled": true,
            "hostNameSslStates": [
              {
                    "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '.azurewebsites.net')]",
                "sslState": "Disabled",
                "hostType": "Standard"
              },
              {
                    "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '.scm.azurewebsites.net')]",
                "sslState": "Disabled",
                "hostType": "Repository"
              }
            ],
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('serverfarms_FunctionPlan_name'))]",
            "siteConfig": {
                    "numberOfWorkers": 1,
              "acrUseManagedIdentityCreds": false,
              "alwaysOn": false,
              "http20Enabled": false,
              "functionAppScaleLimit": 200,
              "minimumElasticInstanceCount": 0
            }
            }
        },
        {
            "type": "Microsoft.Web/sites/config",
          "apiVersion": "2022-03-01",
          "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '/web')]",
          "location": "West US 2",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('sites_fn_3sjvfqv5e3qmc_name'))]"
          ],
          "properties": {
                "numberOfWorkers": 1,
            "defaultDocuments": [
              "Default.htm",
              "Default.html",
              "Default.asp",
              "index.htm",
              "index.html",
              "iisstart.htm",
              "default.aspx",
              "index.php"
            ],
            "managedPipelineMode": "Integrated",
            "virtualApplications": [
              {
                    "virtualPath": "/",
                "physicalPath": "site\wwwroot",
                "preloadEnabled": false
              }
            ]
          }
        },
        {
            "type": "Microsoft.Web/sites/functions",
          "apiVersion": "2022-03-01",
          "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '/MyHttpTriggeredFunction')]",
          "location": "West US 2",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('sites_fn_3sjvfqv5e3qmc_name'))]"
          ],
          "properties": {
                "config": {
                    "disabled": false,
              "bindings": [
                {
                        "name": "req",
                  "type": "httpTrigger",
                  "direction": "in",
                  "authLevel": "function",
                  "methods": [
                    "get"
                  ]
                },
                {
                        "name": "$return",
                  "type": "http",
                  "direction": "out"
                }
              ]
            },
            "language": "CSharp",
            "isDisabled": false
          }
        },
        {
            "type": "Microsoft.Web/sites/functions",
          "apiVersion": "2022-03-01",
          "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '/Timer-Trigger')]",
          "location": "West US 2",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('sites_fn_3sjvfqv5e3qmc_name'))]"
          ],
          "properties": {
                "config": {
                    "bindings": [
                      {
                        "name": "myTimer",
                  "type": "timerTrigger",
                  "direction": "in",
                  "schedule": "0 */500* * * *"
                      }
              ]
            },
            "files": null,
            "test_data": "",
            "invoke_url_template": null,
            "language": "CSharp",
            "isDisabled": false
          }
        },
        {
            "type": "Microsoft.Web/sites/hostNameBindings",
          "apiVersion": "2022-03-01",
          "name": "[concat(parameters('sites_fn_3sjvfqv5e3qmc_name'), '/', parameters('sites_fn_3sjvfqv5e3qmc_name'), '.azurewebsites.net')]",
          "location": "West US 2",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('sites_fn_3sjvfqv5e3qmc_name'))]"
          ],
          "properties": {
                "siteName": "fn-3sjvfqv5e3qmc",
            "hostNameType": "Verified"
          }
        }
      ]
    }
    
    • 部署到 Azure 后,它将如下所示。

    • 点击转到资源组它会转到资源组如下。

    • 后藤函数应用并导航到您将找到的功能,如下所示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-30
      • 1970-01-01
      • 2022-06-23
      • 1970-01-01
      • 2016-10-22
      • 2022-11-11
      • 1970-01-01
      • 2016-06-16
      相关资源
      最近更新 更多