代码之家  ›  专栏  ›  技术社区  ›  David Yates

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

  •  1
  • David Yates  · 技术社区  · 6 年前

    我有两个不同的azure功能应用(a&b),它们使用相同的应用服务计划,而不是消费计划。azure功能应用a位于资源组1中,azure功能应用b位于资源组2中。如果我的应用服务计划位于资源组1中,则我可以按如下方式编写创建azure功能应用a的脚本:

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

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

    有没有办法告诉azure cli应用服务计划在资源组1中,尽管我正在尝试在资源组2中创建azure函数应用?

    2 回复  |  直到 6 年前
        1
  •  2
  •   Michael B    6 年前

    编辑以添加-

    从埃万德罗的回答开始,仔细观察 source code 这是个错误,不可能。

    这是因为代码没有解析资源ID,而是接受应用程序名并传递--resource组变量(我已经为此提交了一个修复程序)

    在纠正之前,唯一的解决方案是在同一个rg中创建一个应用程序,然后将其移动到所需的位置。

    原始答案

    如果您查看文档 az functionapp create

    对于 --plan 下面是-

    功能应用服务计划的名称或资源ID。使用“appservice plan create”获取一个。

    如果您指定了一个名称,它希望在同一资源组中找到它,如果它不在同一资源组中,则需要发送完整的资源id

    像这样的东西

    $ID = $(az appservice plan show --name $name --resource-group $RG | jq '. | .id')
    
    az functionapp create --resource-group $serverData.ResourceGroupName \
      --plan  $ID \
      --name $serverData.FunctionAppName \
      --storage-account $serverData.LrsStorageAccountName
    
        2
  •  3
  •   Evandro de Paula    6 年前

    文档 https://docs.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create 声明以下关于 --计划 参数:

    姓名或 资源标识 功能应用服务计划的…

    这使我相信有可能通知资源ID(例如 /订阅/{subscription id}/resourcegroups/{resource group name}/providers/microsoft.web/serverfarms/{app service plan name} )以及--plan参数。

    所以,根据你的情况,我 创建AZ FunctionApp 路过 应用服务计划资源ID --计划 参数。此外,我还添加了 --调试 选项获取有关执行的更多详细信息。在下面查找命令输出的最后一部分和错误消息:

    ---命令---

    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