azure function app - 如何更新 local.settings.json 文件中的 AzureWebJobsStorage?

发布于 2025-01-14 00:22:44 字数 3916 浏览 3 评论 0原文

问题

azure function (v4) 应用的部署脚本不会像我们的其他应用程序一样更新我的 local.settings.json - AzureWebJobsStorage 值。

代码

执行以下操作的部署脚本:(在大多数情况下仅显示高级详细信息)

#set the subscription we want to use
az account 

#create resource group
az group create ...

#deploy ARM Template
az deployment group create `
     --resource-group $resourcegrp `
     --template-file "./arm_templates/apptemplate.json"

#update local.settings
func settings add FUNCTIONS_WORKER_RUNTIME dotnet

#update connection string for the storage account  
func azure storage fetch-connection-string $storageAccount.name

#deploy function app using local settings. 
func azure functionapp publish $fnApp.name --publish-local-settings -i --overwrite-settings -y

local.settings.json

这是我的本地设置文件的样子:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=somename;AccountKey=aSuperOldKeyValue;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "StorageQueue": "DefaultEndpointsProtocol=https;AccountName=somename;AccountKey=freshKey,
    "ServiceBus": ""
  },
  "ConnectionStrings": {}

 }

ARM模板 就 appSettings 而言,ARM 模板如下所示:

 "properties": {
    "reserved": true,
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
    "siteConfig": {
      "linuxFxVersion": "DOTNETCORE|6.0",
      "appSettings": [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "AzureWebJobsStorage",
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
        },
        {
          "name": "FUNCTIONS_EXTENSION_VERSION",
          "value": "~4"
        },
        {
          "name": "FUNCTIONS_WORKER_RUNTIME",
          "value": "dotnet"
        }
      ]
    }

部署结果/工件

当我部署时,我看到此错误消息:

Getting site publishing info... 
Creating archive for current directory... 
Uploading 13.01 MB [##############################################################################]  
Upload completed successfully. 
Deployment completed successfully.  
App setting AzureWebJobsStorage is different between azure and local.settings.json Overwriting setting in azure with local value because '--overwrite-settings [-y]' was specified.  
Setting FUNCTIONS_WORKER_RUNTIME = ****  
Setting StorageQueue = ****  
Setting ServiceBus = ****

I can of course, remove the overwrite instructions 然后它会提示我问我是否想用本地值覆盖天蓝色值。我不得不说不能确保上游应用程序实际工作。

其他评论

我已将此脚本与我们拥有的类似功能应用程序的另一个部署脚本进行了比较,但我确实看不出逻辑上有任何直接差异。但另一个应用程序确实会在每次运行脚本时正确更新 AzureWebJobsStorage(并且它具有基本相同的步骤、相同的顺序)。这两个脚本之间有一个很大的区别 - 尽管我还不确定它是否是罪魁祸首 - 有效的脚本是 azure 函数版本 3,而这个新应用程序正在运行版本 4。

我将在谷歌上搜索看看是否这是我问题的根本原因,但如果有人可以帮助我。目标是确保此配置设置的值始终是上游应用程序中的最新值,并将该值填充到我的 local.settings.json 文件中。

编辑1

因此,尽管我希望它自动更新,但出于学习目的,我将 AzureWebJobsStorage 更改为如下所示:

"AzureWebJobsStorage": "UseDevelopmentStorage=true"

根据答案中的建议。 在我的 csproj 中,我有以下内容:

<None Update="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>

这会破坏我的应用程序,因为它复制了上游的 "AzureWebJobsStorage": "UseDevelopmentStorage=true" ,因此该应用程序不再工作。

Problem

A deployment script for an azure function (v4) app does not update my local.settings.json - AzureWebJobsStorage value like our other applications.

Code

The deployment script that does the following: (only showing high level details in most cases)

#set the subscription we want to use
az account 

#create resource group
az group create ...

#deploy ARM Template
az deployment group create `
     --resource-group $resourcegrp `
     --template-file "./arm_templates/apptemplate.json"

#update local.settings
func settings add FUNCTIONS_WORKER_RUNTIME dotnet

#update connection string for the storage account  
func azure storage fetch-connection-string $storageAccount.name

#deploy function app using local settings. 
func azure functionapp publish $fnApp.name --publish-local-settings -i --overwrite-settings -y

local.settings.json

This is what my local settings file looks like:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=somename;AccountKey=aSuperOldKeyValue;EndpointSuffix=core.windows.net",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "StorageQueue": "DefaultEndpointsProtocol=https;AccountName=somename;AccountKey=freshKey,
    "ServiceBus": ""
  },
  "ConnectionStrings": {}

 }

ARM Template
Here's what the ARM template looks like as far as the appSettings is concerned:

 "properties": {
    "reserved": true,
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanPortalName'))]",
    "siteConfig": {
      "linuxFxVersion": "DOTNETCORE|6.0",
      "appSettings": [
        {
          "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
          "value": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName')), '2015-05-01').InstrumentationKey]"
        },
        {
          "name": "AzureWebJobsStorage",
          "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';EndpointSuffix=', environment().suffixes.storage, ';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value)]"
        },
        {
          "name": "FUNCTIONS_EXTENSION_VERSION",
          "value": "~4"
        },
        {
          "name": "FUNCTIONS_WORKER_RUNTIME",
          "value": "dotnet"
        }
      ]
    }

Deployment Results / Artifacts

When I deploy, I see this error message:

Getting site publishing info... 
Creating archive for current directory... 
Uploading 13.01 MB [##############################################################################]  
Upload completed successfully. 
Deployment completed successfully.  
App setting AzureWebJobsStorage is different between azure and local.settings.json Overwriting setting in azure with local value because '--overwrite-settings [-y]' was specified.  
Setting FUNCTIONS_WORKER_RUNTIME = ****  
Setting StorageQueue = ****  
Setting ServiceBus = ****

I can of course, remove the overwrite directive and then it will prompts me to ask if i want to overwrite the azure value with the local. I have to say no ensure the upstream application actually works.

Additional Comments

I've compared this script with another deployment script for a similar function app we have and I can't really see any immediate differences in logic. But the other app does correctly get the AzureWebJobsStorage updated each time the script is run (and it has basically the same steps, in the same order). There is one big difference between the two scripts - although I'm not sure yet if it's the culprit - the one that works is azure function version 3 and this new app is running version 4.

I'm going to be googling to see if that's the root cause of my problem but if someone can help me. The goal is to make sure that the value of this config setting is always the latest in the upstream application, and to have that value populated in my local.settings.json file.

Edit 1

So although I want it to be autoupdated, for learning purposes, I changed AzureWebJobsStorage to look like this:

"AzureWebJobsStorage": "UseDevelopmentStorage=true"

per the suggestion in the answer.
In my csproj, I had the following:

<None Update="local.settings.json">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>

This breaks my app because it copies the "AzureWebJobsStorage": "UseDevelopmentStorage=true" upstream and so the app doesn't work anymore.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人骨 2025-01-21 00:22:44

要更新 local.settings.json 文件中的 AzureWebJobsStorage,您可以尝试以下方法:

  1. 设置UseDevelopmentStorage=true
  2. 右键单击 local.settings.json,转到属性,将“复制到输出目录”“不复制”更改> 到“始终复制”。

参考文献:local.settings.json 中缺少 AzureWebJobsStorage 值 , local.settings.json 本地开发中缺少 AzureWebJobsStorage 的值在 Visual Studio 2017https://www.koskila.net/how-to-fix-missing-value-for-azurewebjobsstorage-in-local-settings-json-when-youre-debugging-azure-functions-locally/

To update the AzureWebJobsStorage inlocal.settings.json file, you can try following ways:

  1. Set UseDevelopmentStorage=true
  2. Right-click on local.settings.json, go to properties, change "Copy to Output directory" from "Do not copy" to "Copy always".

References: Missing value for AzureWebJobsStorage in local.settings.json , Missing value for AzureWebJobsStorage in local.settings.json local development in Visual Studio 2017 and https://www.koskila.net/how-to-fix-missing-value-for-azurewebjobsstorage-in-local-settings-json-when-youre-debugging-azure-functions-locally/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文