Azure Event Grid Filters

In this post I’m taking a deeper look at Azure Event Grid filters and using them in Azure Logic Apps. Take note that Azure Event Grid was in preview at the time of writing and there were a few hiccups.

Event Data Schema

I used this quickstart from the Azure team as a base. It used this JSON file for the event data.

[
 {
 "id": "'"$RANDOM"'",
 "eventType": "recordInserted",
 "subject": "myapp/vehicles/motorcycles",
 "eventTime": "'`date +%Y-%m-%dT%H:%M:%S%z`'",
 "data":{
 "make": "Ducati",
 "model": "Monster"
 }
 }
]

You can read the full schema documentation here. The id, eventType, subject and eventTime properties are required and most of them are used internally by Azure Event Grid. The data object is for your custom data and can be any JSON object.

Filters

An event subscription can contain prefix, suffix and event type filters.

 

 

 

 

 

 

 

 

 

The event type filter will filter on the eventType property. You can add multiple event types separated by a semi colon, wild cards do not work.The prefix and suffix filters will filter on the subject property. You cannot add multiple values in a prefix or suffix filter and wild cards do not work.
Side Note: The Prefix filter was read only in the Azure portal when I tested it but you could set it using the Azure CLI.

az eventgrid topic event-subscription create --name eventsubprefic --endpoint https://requestb.in/1fy6fab1 -g gridResourceGroup --topic-name testtopic5765 --subject-begins-with test

You can read the full event subscription schema here.

Using Azure Event Grid In A Logic App

I used the quick start example here as a base and used the SendGrid connector to notify me of events in a resource group. At the time of writing Azure Event Grid was still in preview so there will be some problems which are pointed out in the documentation. You have to login with an Azure Directory user or use a Service Principal connection for the Azure Event Grid connector in the Logic App designer. If you use a Microsoft live account it won’t be able to connect to Azure.

I also had a problem accessing all the event properties in the dynamic content window, the body wasn’t showing for instance. To work around it, switch to the expression editor and start typing the property names to see the full list. Now you can switch back to the dynamic content window and select the properties you want in the email body.

 

 

 

 

 

 

 

 

 

You can apply prefix and suffix filters by clicking on Show advanced options but not on the eventType.

 

 

 

 

 

 

 

 

If you have a requirement to filter on other properties you can do it by adding a condition statement and writing some code. The quick start I mentioned earlier shows exactly how to do this.

Francois Delport

Published by

Francois Delport

I am a cloud and devops consultant, technology fan and previously a professional C# developer with a keen interest in system design and architecture. Currently I am involved in projects using Azure, the Microsoft stack and DevOps. I am based in Melbourne, Australia. Email: [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *