使用AZ CLI链接SWA预览部署至Azure函数非默认槽遇错,如何指定槽?
尝试通过以下AZ CLI命令将静态Web应用(SWA)的预览部署链接到Azure函数的非默认部署槽:az staticwebapp functions link --function-resource-id "/subscriptions/[sub-id]/resourceGroups/[resource-group-name]/providers/Microsoft.Web/sites/[func-name]/slots/[slot-name]" -n [swa-name] -g [swa-rg-name] --environment-name "[env-name]" --force
执行后收到错误提示:ERROR: --function-resource-id must specify a function resource ID. To get resource ID, use the following commmand, inserting the function group/name as needed: az functionapp show --resource-group "[FUNCTION_RESOURCE_GROUP]" --name "[FUNCTION_NAME]" --query id
请问应如何正确指定Azure函数的部署槽?
问题出在你直接使用了部署槽的资源ID,但az staticwebapp functions link命令要求的是函数应用本身的资源ID,而非部署槽的ID。要链接到非默认部署槽,需通过额外参数指定槽名,操作步骤如下:
第一步:获取函数应用的基础资源ID(不带部署槽路径)
az functionapp show --resource-group "[FUNCTION_RESOURCE_GROUP]" --name "[FUNCTION_NAME]" --query id -o tsv第二步:使用获取到的函数应用ID,加上
--slot参数指定目标部署槽,修改后的命令如下:az staticwebapp functions link --function-resource-id "[函数应用资源ID]" -n [swa-name] -g [swa-rg-name] --environment-name "[env-name]" --slot "[slot-name]" --force
执行上述修改后的命令,即可将SWA的预览环境正确链接到指定的Azure函数部署槽。
内容的提问来源于stack exchange,提问作者Motoko

