Search code examples
c#azureazure-functionsazure-managed-identity

Azure durable functions are not invoked when used with Q trigger using managed identity


Working with managed identity with durable functions and is working fine. Once we add the Q trigger function with the same storage account using managed identity then the things arenot working.

Issue is the durable functions are not getting invoked and the runtime status is pending.

Also the Q trigger function app is not triggering when the Q gave data in it. So need advice like any dependency issue with both durable functions and Q trigger function with managed identity.

If we use only durable or only Q trigger with managed identity - it will work fine. Problem is when we use both.

    [FunctionName("qtrigger")]
    public void Run([QueueTrigger("b2b2devpoc", Connection = "QueueConnection")]string myQueueItem, ILogger log)
    {
        log.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
    }

Durable function code:

   **[FunctionName("Function1")]
   public static async Task<List<string>> RunOrchestrator(
       [OrchestrationTrigger] IDurableOrchestrationContext context)
   {
       var outputs = new List<string>();
       // Replace "hello" with the name of your Durable Activity Function.
       outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Tokyo"));
       outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "Seattle"));
       outputs.Add(await context.CallActivityAsync<string>(nameof(SayHello), "London"));
       // returns ["Hello Tokyo!", "Hello Seattle!", "Hello London!"]
       return outputs;
   }
   [FunctionName(nameof(SayHello))]
   public static string SayHello([ActivityTrigger] string name, ILogger log)
   {
       log.LogInformation("Saying hello to {name}.", name);
       Thread.Sleep(3000);
       return $"Hello {name}!";
   }
   [FunctionName("testfunction")]
   public static async Task<HttpResponseMessage> HttpStart(
       [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
       [DurableClient] IDurableOrchestrationClient starter,
       ILogger log)
   {
       
       // Function input comes from the request content.
       string instanceId = await starter.StartNewAsync("Function1", null);
       log.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);
       return starter.CreateCheckStatusResponse(req, instanceId);
   }

}**

Durable function response:

{ "name": "Function1", "instanceId": "10f1f4cb1a5245499aa2aacafcf488cc", "runtimeStatus": "Pending", "input": null, "customStatus": null, "output": null, "createdTime": "2024-07-31T07:16:19Z", "lastUpdatedTime": "2024-07-31T07:16:19Z" }

Env Variable:

enter image description here

enter image description here


Solution

  • I have made following changes to get both the Queue trigger function and the Durable function run in a single function app using user assigned managed identity.

    • I have created the function app in App service plan. Throughout the process I am also using a single storage account (V2).
    • Make sure, you have the below Environment Variables in the function app. AZURE_CLIENT_ID contains the value of clientId of user assigned managed identity.

    enter image description here

    • I have granted given permissions to the user assigned managed identity in the storage account.

    enter image description here

    • I am able to get the expected response from queue triggered function as well as from durable function.

    enter image description here

    enter image description here

    You can check the associated application insight for any exception raised by function app.