Is there a way to read Azure Queue Storage in Queue Trigger Azure function using managed identity without using connection string in the code

Dixan Thomas 105 Reputation points
2023-06-28T05:59:01.77+00:00

Currently I'm using Connection string in AzureWebStorage for the connection to Queue. I need it without connection string and only by using managed identity

using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class QueueTriggerFunction
{
    [FunctionName("QueueTriggerFunction")]
    public static void Run(
        [QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string message,
        ILogger log)
    {
        log.LogInformation($"Processing queue message: {message}");

        // Add your processing logic here
    }
}

Here I'm specifying AzureWebJobsStorage value as my Connection String of the storage. But I want remove the dependency on Connection String and get it by using Managed Identity

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,930 questions
{count} votes

Accepted answer
  1. navba-MSFT 27,550 Reputation points Microsoft Employee Moderator
    2023-06-28T07:04:55.6833333+00:00

    @Dixan Thomas Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I understand that you want to use Managed Identity to interact with queue storage from FuntionApp instead of using Connection String.

    You need to first leverage v5.0 version of Microsoft.Azure.WebJobs.Extensions.Storage.Queues. This version introduces the ability to connect using an identity instead of a secret. For a tutorial on configuring your function apps with managed identities, see the creating a function app with identity-based connections tutorial.

    dotnet add package Microsoft.Azure.WebJobs.Extensions.Storage.Queues --version 5.0.0

    Once the above steps are followed, Your application may require additional permissions based on the code you write. You need to have the below RBAC permissions on Azure Storage for your Function APP.

    Trigger Storage Queue Data Reader, Storage Queue Data Message Processor
    Output binding Storage Queue Data Contributor, Storage Queue Data Message Sender

    Below settings are also needed in your json:

    "AzureWebJobsStorage__queueServiceUri": "https://mystorage.queue.core.windows.net/",
    "AzureWebJobsStorage__credential": "managedidentity"
    

    More Info about the above settings are below:

    AzureWebJobsStorage__credential Defines how a token should be obtained for the connection. This setting should be set to "managedidentity" if your deployed Azure Function intends to use managed identity authentication. This value is only valid when a managed identity is available in the hosting environment.
    AzureWebJobsStorage__queueServiceUri The data plane URI of the queue service of the storage account, using the HTTPS scheme. https://<storage_account_name>.queue.core.windows.net

    References:
    https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-queue?tabs=in-process%2Cextensionv5%2Cextensionv3&pivots=programming-language-csharp#install-extension

    Also refer : Azure Functions - use queue trigger with managed identity

    ** Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.