使用二头肌的 Azure Functionapp 部署:请求正文中不存在属性对象
Posted
技术标签:
【中文标题】使用二头肌的 Azure Functionapp 部署:请求正文中不存在属性对象【英文标题】:Azure Functionapp Deployment using Bicep: Properties object is not present in the request body 【发布时间】:2022-01-01 00:58:18 【问题描述】:我正在尝试使用二头肌文件部署一个新的 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)
虽然属性对象是明确定义的。当我省略整个属性对象时,我收到一个错误,即属性是一个不应该是的值(可能为 null)。 有什么想法吗?
更新: functionApp 的部分很好,不是问题。我在二头肌文件中有另一个资源,我忘记了哪个缺少属性对象。因为它在 EOF 并且只有 4 行,所以没有看到它。谢谢大家
【问题讨论】:
【参考方案1】:以下是使用 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 中找到完整信息,并查看此doc 的相关信息。
【讨论】:
即使使用您的示例,我也会收到相同的错误消息。但是,资源已创建,甚至 functionApp 也已成功运行。也许只是powershell有问题?你能告诉我你的 pwsh 版本吗?我的是 7.2.0 在 macOS 上【参考方案2】:按照建议检查部署操作 (https://aka.ms/DeployOperations)。转到您部署的资源组并检查“部署”,您将看到部署失败的原因。
【讨论】:
陈述了我在第一篇文章中已经发布的相同错误以上是关于使用二头肌的 Azure Functionapp 部署:请求正文中不存在属性对象的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 Microsoft.Cdn 配置文件/秘密来启用证书?