I have an Azure Function (C#) that is triggered by an Event Grid. I am having difficulty debugging my Function locally as it can only be triggered via the Event Grid.
I'm not sure if there is a way to wire the Event Grid up to my local host address for my Function? I have tried using a Web Hook but it only support HTTPS which my localhost uses HTTP.
public static void Run([EventGridTrigger]EventGridEvent eventGridEvent, ILogger log)
{
ID = eventGridEvent.Subject;
log.LogInformation($"ID: {ID.ToString()}");
}
Any advice is appreciated.
I found this blog post that helped me resolve this when debugging event grid azure function locally: https://blog.mcilreavy.com/articles/2018-12/debug-eventgrid-triggered-azure-function
One piece that was missing in my case was the aeg-event-type header.
aeg-event-type: Notification
After adding it, I was able to debug locally using this url:
http://localhost:7071/runtime/webhooks/EventGrid?functionName=nameOfYourFunction
And include this event json in the request body, something like this:
[
{
"id": "'1",
"eventType": "yourEventType",
"eventTime":"10:59:00.000",
"subject": "subject1",
"data":{"make": "Ducati", "model": "Monster"},
"dataVersion": "1.0"
}
]
Actually, there is a nice and easy way of doing this using a ngrok as a tunnel. So you basically create a EventGrid Subscription that publishes your events to your ngrok tunnel (e. g. https://ec291dd9.ngrok.io/runtime/webhooks/EventGrid?functionName=myfunc) and start debugging your function in Visual Studio. You don't need to change your function at all.
This approach is also well documented from Microsoft: Azure Function Event Grid Trigger Local Debugging
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With