Search code examples
azuredockerazure-functionspulumiazure-container-apps

How can I make an azure function within an azure container app subscribe to an event hub?


I have an Azure function which has multiple functions hosted within an Azure Container App, along with an event grid. I need the azure function to subscribe to the event grid.

I read the following link and understand i need to use webhooks- Get Webhook url of a Function App in ARM to use for Event Grid Subscription

However the above stackoverflow question is only for an azure function. Where the URL is easy to recreate. How do i go about recreating the URL for an azure function within the container app.

I am not sure if webhooks are also the correct way for the azure function to subscribe to the event grid.

All of this needs to be eventually deployed by pulumi. Following is my pulumi code block:

                var containerAppWebhookEndpoint = $"https://{containerApp.Name}.eastus2.azurecontainerapps.io/api/ProcessNotification"; // Replace 'myfunction' with your function's name

                _ = new EventSubscription("container-app-event-subscription", new ()
                {
                    Destination = new WebHookEventSubscriptionDestinationArgs
                    {
                        EndpointUrl = containerAppWebhookEndpoint,
                        EndpointType = "WebHook"
                    },
                    
                    EventDeliverySchema = EventDeliverySchema.EventGridSchema,
                    RetryPolicy = new RetryPolicyArgs
                    {
                        MaxDeliveryAttempts = 30,
                        EventTimeToLiveInMinutes = 1440
                    },
                    Scope = eventGridTopic.Id,
                    
                }, new CustomResourceOptions
                {
                    Provider = _context.Provider,
                });
                

Tried recreating the API url such as https://{functionApp}.azurewebsites.net/runtime/webhooks/EventGridExtensionConfig?functionName={function}&code={masterKey}

Azure portal image for container app


Solution

  • I have an Azure Function hosted within an Azure Container App.

    enter image description here

    • The issue here is that Azure Functions within a Container App have a different structure compared to standalone Azure Functions, and their URLs are not structured in the same way. Recreating the URL in that format is not applicable for Azure Functions hosted within a Container App.

    • To correctly construct the webhook URL for an Azure Function within a Container App, you typically need to rely on the URL pattern defined by the Azure Functions runtime for your specific deployment.

    Construct the webhook URL in Pulumi code for an Azure Function within a Container App.

    Make sure to give the below webhook URL for the creation.

    enter image description here

    Check this is in active and click on ping.

    enter image description here