Search code examples
.netazureazure-functionsazure-queuesazure-functions-runtime

Azure functions queue trigger with managed identity


I created an isolated process Azure functions for queue trigger. Based on link I created managed identify string using <CONNECTION_NAME_PREFIX>__queueServiceUri. This property works locally when I specify in local.settings.json. But it doesn't work when I specify in appsettings.json. Below is my program.cs code

var configuration = new ConfigurationBuilder().AddEnvironmentVariables()
    .AddCommandLine(args)
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
    .Build();

var host = new HostBuilder().ConfigureHostConfiguration(config => {
config.AddConfiguration(configuration);
}).ConfigureFunctionsWorkerDefaults().Build();

Function code:

 [Function("BlobQueueTrigger")]
    public async Task RunAsync([QueueTrigger("datablobqueue", Connection = "blobQueue")] string blobQueueItem)
    {}

Property in appsettings:

"blobQueue__queueServiceUri": "https://mydatastorage.queue.core.windows.net"

Solution

  • According to the documentation you referenced above, blobQueue__queueServiceUri must be defined as an Environment Variable, not in appsettings.json. This means you need to set it as an Application Setting in the portal. When working locally, values set in local.settings.json are indeed loaded as Environment Variables

    Been a while since I dug into this, but I think it needs to access that value before it actually starts your process. Hence the custom configuration providers you have defined in Program.cs aren't yet loaded.