azure - 如何导出和导入Azure Function的 "application settings"

标签 azure azure-functions

如何导出和导入Azure函数的“应用程序设置”?我已添加按键,需要移至新功能应用程序。请指导。

最佳答案

这里你有几个选择:

手动

您可以通过以下方式手动完成:

  1. 转到https://resources.azure.com
  2. 在您的应用设置所在位置搜索您的应用。
  3. 转到“应用设置” View 并复制属性中的所有 JSON

enter image description here

  • 转到您的新应用,导航至“应用设置”并点击“编辑”,然后将所有内容放入属性集合中。
  • 自动化:

    您可以使用 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/

    相关文章:

    javascript - 如何使用 azure 函数和 cosmos Node sdk 检查 cosmosDB 中的项目是否已过期?

    azure - 限制从 Blob 存储中的静态网站调用 Azure 函数?

    azure - 配置文件并在 Azure-Functions 中检索

    typescript - Playwright - 当 Chromium 位于 node_modules 中时无法启动 Chromium(Azure 函数 - Linux 和 Windows)

    Azure Web 应用程序 ARR 关联 token 场景

    azure - Web 角色经常崩溃

    c# - 如何在 Azure Functions 中配置 session cookie?

    C# 如何更新 Azure IoT 中心设备所需的孪生属性

    iis - 本地 IIS 上的 Windows Azure Web 角色

    azure - 如何复制 Azure Functions 应用程序?