Search code examples
c#azure-active-directoryazure-functionsazure-managed-identityazure-queues

"Storage account connection string 'AzureWebJobsStorage' does not exist." when starting Azure Function with Queue Trigger and AAD Identity


We have an Azure Function with Queue Trigger that was working just fine until some weeks ago, when the infrastructure guys switched to AAD Identity. Ever since, we have been getting the following exception whenever the Function starts:

Error indexing method 'MyFunctionName' Storage account connection string 'AzureWebJobsStorage' does not exist. Make sure that it is a defined App Setting.

According to this tutorial, the aplication setting AzureWebJobsStorage had to be changed to AzureWebJobsStrorage__accountName. This was correctly done: enter image description here

However, ever since this change was applied, the exception above has been thrown. As a workaround, we additionally re-added the old setting AzureWebJobsStorage, which led to the function working again.

We cannot seem to find out, where the issue lies. We have followed all the steps described in the above-mentioned tutorial, and also other solutions found in blog posts and other sites, such as adding connection names in the [QueueTrigger] attribute as well as local.settings.json and appsettings.json, adding AzureWebJobsStorageAccount__credential (with value managedidentity) and AzureWebJobsStorageAccount__queueServiceUri to the settings, and so on. Nothing seems to be helping, though.

What are we missing? As far as I understood the tutorial, as long as the access to the storage account is granted and the setting is renamed (and its value changed, of course), all should be fine, without even needing to tough the code.

Edit:
here is the current local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

Solution

  • I also got the same error in my environment below,

    enter image description here

    I added below setting in function app> Environment variables> App settings as below,

    AzureWebJobsStrorage__accountName : <storage_name>

    enter image description here

    I switched on the identity in function app at Azure portal as below,

    enter image description here

    I assigned the Storage Queue Data Contributor role to the function app in the storage account at the Azure portal as below,

    enter image description here

    And, I assigned the owner role to the newappk AAD app in the storage account at the Azure portal as below,

    enter image description here

    local.settings.json :

    {
        "IsEncrypted": false,
      "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
        "QueueConnection__queueServiceUri": "https://<storage_name>.queue.core.windows.net/"
      }
    }
    

    Code:

    I tried a simple queue trigger code below,

    using System;
    using Azure.Storage.Queues.Models;
    using Microsoft.Azure.Functions.Worker;
    using Microsoft.Extensions.Logging;
    
    namespace FunctionApp39
    {
        public class Function1
        {
            private readonly ILogger<Function1> _logger;
    
            public Function1(ILogger<Function1> logger)
            {
                _logger = logger;
            }
    
            [Function(nameof(Function1))]
            public void Run([QueueTrigger("myqueue", Connection = "QueueConnection")] QueueMessage message)
            {
                _logger.LogInformation($"C# Queue trigger function processed: {message.MessageText}");
            }
        }
    }
    

    Output:

    It runs successfully as below,

    enter image description here

    I added a message to the queue like below in the storage account at the Azure portal,

    enter image description here

    enter image description here

    Then, I published this to function app as below,

    enter image description here

    I added the QueueConnection_queueServiceUri in the App setting below,

    QueueConnection__queueServiceUri : "https://<storage_name>.queue.core.windows.net/"

    enter image description here

    Then, I sent a message to the queue and got it triggered in Application insights as below,

    enter image description here

    I can see the message in the monitor function also as below,

    enter image description here