0

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.

dot
  • 14,928
  • 41
  • 110
  • 218

1 Answers1

0

To update the AzureWebJobsStorage in local.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/

Madhuraj Vadde
  • 1,099
  • 1
  • 5
  • 13
  • there is no properties option for me in vscode when I right click on the file. But in the csproj file, I see some relevant entries. please see edit 1 – dot Mar 15 '22 at 13:52
  • You can refer to https://learn.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string and if that doesn't resolve your issue, you can open an issue on GitHub: https://github.com/Azure/azure-functions-core-tools/issues – Madhuraj Vadde Mar 16 '22 at 04:30
  • yeah it must be a bug because ... when I test the actual functions AFTER i've used the CopyToOutputDirection option, i'm getting many errors locally and upstream. – dot Mar 16 '22 at 14:58
  • 1
    please share us the bug ID (github link) if you file one – Madhuraj Vadde Mar 16 '22 at 15:03
  • [AzureWebJobsStorage won't update anymore.](https://github.com/Azure/azure-functions-core-tools/issues/2988) – Ecstasy Apr 06 '22 at 06:47