Seth Vinod
3 min readApr 13, 2021

--

Develop and debug Azure Function for Event Grid Trigger Part 1

I have been struggling with Debugging Azure Functions for Event Grid Trigger from last few days. Development is a bit easy and straight forward as lot of content is available on net, however debugging took me some time to find out a good approach.

Azure Function Overview

Azure Function is a serverless solution. Serverless means, you need not worry about deploying and maintaining hardware (servers) and software (OS, development package etc), everything is managed by cloud provider. its like compute-on-demand. Azure Functions are like simple functions written in any language of choice(python, c# etc).

Azure Function Invocation

Azure Functions can be invoked in response to various trigger(standard triggers defined by Azure) types. we will learn how to debug an Azure Function written for Event Grid Trigger.

what is Event Grid

Azure Service that captures various events generated by publishers.

What is Publisher

Publisher is a service, user or organization that sends the event to Event Grid in response to some action.

Event sources

where the event occurs? Publisher publishes an event. For example, an Azure blob storage account is a publisher, and a blob upload or delete is an event. Event Handlers receives and process the events. Azure functions have built in support for handling and processing Event Grid events.

Topics

Event grid uses topics to publish an event. Topic is a collection of related events and subscriber then subscribes to the required topics.

The architecture is depicted below. when u upload a blob an event is published to event grid which will be captured by the azure function who has subscribed this event.

Event Grid topic cannot be run locally. so how to debug or test azure functions that subscribe to event grid?

Event Grid supports two schemas:

  1. Event Grid Schema
  2. Cloud Event Schema

How to provide event data to azure function when in local mode

Use Sample Event Schema

when we create an azure function using vs code a sample json file for Event Grid schema is also created (name :- sample.dat). we can use it as an input to our event Grid Trigger type functions. Steps are shown below

  1. Execute the function locally

Press F5 and run the function. you will see the output as shown below in the vs code terminal

2. Use POSTMAN to debug

postman is a well known tool for testing api endpoints, it provides easy interface to construct json and post them to the testing endpoint. open postman and create a request as shown below. yourfunctionname in the url should be your azure function name and the type of verb should be POST.

3. select Body option and then select raw under it as shown above. paste the content of sample.dat(file provided by vscode when the azure function was created) in it. you can paste your custom event content also.

4. go to Header tab and set the content as shown

5. click send and you should see the output as shown below in vs code terminal

Terminal output

Testing using events triggered by azure Event Grid.

I will explain this in the next post

thanks for reading

--

--