【发布时间】:2021-08-24 10:13:15
【问题描述】:
我必须使用通过参数传入的名称为我的 Azure 函数创建一个主机密钥(在 API 管理后端中使用)。 我不知道如何使用 listKeys 通过它的名称获取一个特定的主机密钥。
我正在创建这样的主机密钥,如果我不添加我的输出,这将正常工作
{
"type": "Microsoft.Web/sites/host/functionKeys",
"apiVersion": "2018-11-01",
"name": "[concat(variables('functionSite-name'), '/default/',variables('apim-name'))]",
"properties": {
"name": "[variables('apim-name')]"
}
}
我试过这个,从另一个帖子得到它,但它返回错误: {"code":"DeploymentFailed","message":"至少一项资源部署操作失败。请列出部署操作以了解详细信息。请参阅https://aka.ms/DeployOperations了解使用详情。","details":[{"code": "InvalidResourceNamespace","message":"资源命名空间 'GetVersionPOCApiManagement' 无效。"}]}
[listkeys(concat(variables('functionSite-name'), '/host/default/'),'2016-08-01').functionKeys[variables('apim-name')]]
'functionSite-name' 是我的 Azure 函数的名称 (Microsoft.Web/sites) 'apim-name' 是创建的主机密钥的名称(Microsoft.Web/sites/host/functionKeys)
作为参考我的完整脚本,我使用部署,因为我的 Azure 函数位于另一个资源组中,我需要创建主机密钥,然后将其添加到密钥保管库。之后,我必须配置 API 管理实例以使用此 Azure 函数。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
"apim-name": "eud-sse-poc-apim",
"api-name": "GetVersionPOCApiManagement",
"functionSite-name": "GetVersionPOCApiManagement",
"functionSite-ResourceGroup": "eud-sse-poc-datafactory-rg"
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2020-10-01",
"name": "azureFunctionDeployments",
"resourceGroup": "[variables('functionSite-ResourceGroup')]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Web/sites/host/functionKeys",
"apiVersion": "2018-11-01",
"name": "[concat(variables('functionSite-name'), '/default/',variables('apim-name'))]",
"properties": {
"name": "[variables('apim-name')]"
}
}
],
"outputs": {
"hostKey": {
"type": "string",
"value": "[listkeys(concat(variables('functionSite-name'), '/host/default/'),'2016-08-01').functionKeys[variables('apim-name')]]"
}
}
}
}
}
],
"outputs": {}
}
有什么建议吗?
【问题讨论】:
标签: azure arm-template