[英]How to deploy an Azure Functions App when the Service plan is in a different Resource Group
我有兩個不同的Azure Functions應用程序(A&B),它們使用相同的應用程序服務計划,而不是使用消耗計划。 Azure Function App A在資源組1中,Azure Function App B在資源組2中。如果我的App Service Plan在Resource Group 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應用,但是有沒有辦法告訴Azure CLI應用服務計划在資源組1中?
文檔https://docs.microsoft.com/zh-cn/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create聲明了有關--plan參數的以下內容:
功能應用服務計划的名稱或資源ID ...
這使我相信可以將資源ID(例如/ subscriptions / {Subscription ID} / resourceGroups / {Resource Group Name} /providers/Microsoft.Web/serverFarms/ {App Service Plan Name}告知 - -plan參數。
因此,根據您的情況,我運行az functionapp create來在--plan參數中傳遞App Service 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參數定義的資源組中查找App Service計划(名稱未正確解析)。
我可能會丟失一些東西,可能是文檔問題等。
無論如何,我都提出了以下問題來跟蹤/澄清此問題: https : //github.com/Azure/azure-cli/issues/6532
編輯添加-
從Evandro的答案開始,然后瀏覽源代碼這是一個bug,不可能。
這是因為代碼不會解析資源ID,而是使用應用程序名稱並傳遞--resource-group變量(我已為此提交了修復程序)
在糾正此問題之前,您唯一的解決方案是在同一RG中創建一個應用程序,然后將其移至所需位置。
原始答案
如果您查看z functionapp的文檔,請創建
對於--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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.