如何导出和导入Azure函数的“应用程序设置”?我已添加按键,需要移至新功能应用程序。请指导。
最佳答案
这里你有几个选择:
手动
您可以通过以下方式手动完成:
- 转到https://resources.azure.com
- 在您的应用设置所在位置搜索您的应用。
- 转到“应用设置” View 并复制属性中的所有 JSON
- 转到您的新应用,导航至“应用设置”并点击“编辑”,然后将所有内容放入属性集合中。
自动化:
您可以使用 azure-cli、powershell 或 azure-functions-core-tools 来实现相同的目的。
Powershell:
使用 Azure Powershell 模块 https://learn.microsoft.com/en-us/powershell/azure/overview?view=azurermps-5.4.0
# get the app settings from app1
$resource = Invoke-AzureRmResourceAction -ResourceGroupName <yourResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName "<yourFunctionAppName>/appsettings" -Action list -ApiVersion 2016-08-01 -Force
# update the other app with $resource.Properties
New-AzureRmResource -PropertyObject $resource.Properties -ResourceGroupName <targetResourceGroupName> -ResourceType Microsoft.Web/sites/config -ResourceName "<targetAppName>/appsettings" -ApiVersion 2016-08-01 -Force
azure-functions-core-tools:
该工具的文档位于此处 https://learn.microsoft.com/en-us/azure/azure-functions/functions-run-local
您可以通过运行执行相同的操作
az login
func init myFunctionApp
cd myFunctionApp
# this will fetch your settings and put them in local.settings.json
func azure functionapp fetch-app-settings <yourAppName>
func azure functionapp publish <yourTargetApp> --publish-settings-only
最后一个开关--publish-settings-only
非常重要,如果您只想发布设置,则不要覆盖文件。
azure-cli:
https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
此页面应该有一些有关如何使用 cli 检索和设置应用程序设置的文档 https://learn.microsoft.com/en-us/azure/app-service/scripts/app-service-cli-app-service-storage?toc=%2fcli%2fazure%2ftoc.json
关于azure - 如何导出和导入Azure Function的 "application settings",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49001127/