使用 Bicep 的 Azure Functionapp 部署:请求正文中不存在属性对象

Azure Functionapp Deployment using Bicep: Properties object is not present in the request body

我正在尝试使用二头肌文件部署新的 Azure FunctionApp,以使用基础架构即代码来描述资源。这是二头肌文件:

param name string
param location string = resourceGroup().location
param serverFarmID string

resource functionApp 'Microsoft.Web/sites@2021-02-01' = {
  name: name
  location: location
  kind: 'functionapp'
  properties: {
    serverFarmId: serverFarmID
    enabled: true
    reserved: true
    siteConfig: {
      appSettings: [
        {
          name: 'AzureWebJobsStorage'
          value: 'DefaultEndpointsProtocol=https;AccountName=censored;AccountKey= censored;EndpointSuffix=core.windows.net'
        }
        {
          name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
          value: 'DefaultEndpointsProtocol=https;AccountName=censored;AccountKey= censored;EndpointSuffix=core.windows.net'
        }
        {
          name: 'WEBSITE_CONTENTSHARE'
          value: 'examplefunction'
        }
        {
          name: 'FUNCTIONS_WORKER_RUNTIME'
          value: 'node'
        }
        {
          name: 'FUNCTIONS_EXTENSION_VERSION'
          value: '~3'
        }
        {
          name: 'WEBSITE_NODE_DEFAULT_VERSION'
          value: '~12'
        }
      ]
    }
  }
}

但是我在部署的时候总是报如下错误

Status Message: At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details. (Code: DeploymentFailed)
 - {
  "Code": "BadRequest",
  "Message": "Properties object is not present in the request body.",
  "Target": null,
  "Details": [
    {
      "Message": "Properties object is not present in the request body."
    },
    {
      "Code": "BadRequest"
    },
    {
      "ErrorEntity": {
        "ExtendedCode": "51006",
        "MessageTemplate": "{0} object is not present in the request body.",
        "Parameters": [
          "Properties"
        ],
        "Code": "BadRequest",
        "Message": "Properties object is not present in the request body."
      }
    }
  ],
  "Innererror": null
} (Code:BadRequest)

虽然明确定义了属性对象。当我省略整个 properties 对象时,我收到一条错误消息,指出 properties 是一个不应该的值(可能为 null)。 有什么想法吗?

更新: functionApp 的部分很好,不是问题。我在 bicep 文件中有另一个资源,我忘记了它缺少属性对象。没有看到它,因为它在 EOF 并且只有 4 行。感谢大家

按照建议检查部署操作 (https://aka.ms/DeployOperations)。转到您部署的资源组并检查“部署”,您将看到部署失败的原因。

下面是使用 BICEP 部署 Azure Function App 的示例代码。这将帮助您解决问题。

var location = resourceGroup().location
var suffix = 'azeusfunctionappdev01'

resource storage_account 'Microsoft.Storage/storageAccounts@2020-08-01-preview' = {
  name: 'stg${suffix}'
  location: location
  properties: {
    supportsHttpsTrafficOnly: true
    minimumTlsVersion: 'TLS1_2'
  }
  kind: 'StorageV2'
  sku: {
    name: 'Standard_LRS'
    tier: 'Standard'
  }
}

resource hosting_plan 'Microsoft.Web/serverfarms@2020-06-01' = {
  name: 'asp-${suffix}'
  location: location
  sku: {
    name: 'Y1'
    tier: 'Dynamic'
  }
}

resource function_app 'Microsoft.Web/sites@2020-06-01' = {
  name: 'functionapp-${suffix}'
  location: location
  kind: 'functionapp'
  properties: {
    httpsOnly: true
    serverFarmId: hosting_plan.id
    clientAffinityEnabled: true
    siteConfig: {
      appSettings: [
        {
          'name': 'FUNCTIONS_EXTENSION_VERSION'
          'value': '~3'
        }
        {
          'name': 'FUNCTIONS_WORKER_RUNTIME'
          'value': 'powershell'
        }
        {
          name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
          value: 'DefaultEndpointsProtocol=https;AccountName=${storage_account.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storage_account.id, storage_account.apiVersion).keys[0].value}'
        }
        {
          name: 'WEBSITE_CONTENTSHARE'
          value: '${substring(uniqueString(resourceGroup().id), 3)}-azeus-functionapp-dev01'
        }
        {
          name: 'AzureWebJobsStorage'
          value: 'DefaultEndpointsProtocol=https;AccountName=${storage_account.name};AccountKey=${listKeys(storage_account.id, storage_account.apiVersion)};EndpointSuffix=core.windows.net'
        }
      ]
    }
  }

  dependsOn: [
    hosting_plan
    storage_account
  ]
}

这里还有部署函数的命令

PS C:\> New-AzResourceGroupDeployment -ResourceGroupName "rg-azeusfunctionappdev01" -TemplateFile .\Main.json -Debug

请从这个doc and also check this doc中找到完整的信息和相关信息。