azure - 当服务计划位于不同的资源组中时如何部署 Azure Functions 应用程序

标签 azure azure-functions azure-cli

我有两个不同的 Azure Functions 应用程序(A 和 B),它们使用相同的应用程序服务计划而不是消耗计划。 Azure Function App A 位于资源组 1 中,Azure Function App B 位于资源组 2 中。如果我的应用服务计划位于资源组 1 中,则我可以按照以下脚本编写 Azure Function App A 的创建:

az functionapp create --resource-group $serverData.ResourceGroupName \
  --plan  $serverData.FunctionAppServicePlanName \
  --name $serverData.FunctionAppName \
  --storage-account $serverData.LrsStorageAccountName 

但是,如果我尝试创建 Azure Function App B,上面的命令将不起作用。它告诉我找不到应用程序服务计划。现在,我可以通过门户创建它,但我想编写脚本。

尽管我正在尝试在资源组 2 中创建 Azure Function App,但有没有办法告诉 Azure CLI 应用服务计划位于资源组 1 中?

最佳答案

文档 https://learn.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create声明以下有关 --plan 参数的内容:

Name or resource id of the function app service plan...

这让我相信可以告知资源 ID(例如 /subscriptions/{Subscription Id}/resourceGroups/{Resource Group Name}/providers/Microsoft.Web/serverFarms/{App Service Plan Name})也添加到 --plan 参数中。

因此,根据您的方案,我运行 az functionapp create,并在 --plan 参数中传递应用服务计划资源 ID。此外,我添加了 --debug 选项来获取有关执行的更多详细信息。在下面找到命令输出的最后一部分和错误消息:

--- 命令 ---

az functionapp create --resource-group "abc" --plan "/subscriptions/{Subscription Id}/resourceGroups/azfuncrg/providers/azfunc" --name "functioappname" --storage-account "/subscriptions/{Subscription Id}/resourceGroups/azfuncrg/providers/Microsoft.Storage/storageAccounts/azfuncstorage"

--- 部分输出 ---

...
msrest.http_logger : Response status: 404
msrest.http_logger : Response headers:
msrest.http_logger :     'Cache-Control': 'no-cache'
msrest.http_logger :     'Pragma': 'no-cache'
msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
msrest.http_logger :     'Expires': '-1'
msrest.http_logger :     'x-ms-failure-cause': 'gateway'
msrest.http_logger :     'x-ms-request-id': 'd4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'x-ms-correlation-request-id': 'd4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'x-ms-routing-request-id': 'WESTUS2:20180608T002628Z:d4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
msrest.http_logger :     'X-Content-Type-Options': 'nosniff'
msrest.http_logger :     'Date': 'Fri, 08 Jun 2018 00:26:28 GMT'
msrest.http_logger :     'Content-Length': '139'
msrest.http_logger : Response content:
msrest.http_logger : b'{"error":{"code":"ResourceNotFound","message":"The Resource \'Microsoft.Web/serverFarms/azfunc\' under resource group \'abc\' was not found."}}'
The plan 'azfunc' doesn't exist

根据调试信息,它正在 --resource-group 参数定义的资源组中查找应用服务计划(其名称未正确解析)。

我可能遗漏了一些东西,可能是文档问题等。

无论如何,我提交了以下问题来跟踪/澄清这一点: https://github.com/Azure/azure-cli/issues/6532

关于azure - 当服务计划位于不同的资源组中时如何部署 Azure Functions 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50751305/

相关文章:

azure - Azure Kubernetes 服务中无法访问 Internet 的 Windows Pod

azure - 设置 Azure AD 应用 key 过期通知

Azure CLI 任务不适用于 Windows 构建代理

azure - 如何将表存储表复制到其他表存储

azure - Active Directory 集成应用程序 : Access Token Invalid

azure - 尝试访问已部署的函数时,KUDU 给出禁止错误 - 403

azure - 如何在 Visual Studio 2017 中使用资源组项目自动部署 Function App 内容?

azure - 无法使用 Azure CLI 访问账单信息

azure - 如果安全参数中包含某个字符,则需要帮助停止二头肌部署

c# - Azure SendGrid 提供的授权无效、已过期或已撤销