I love Visual Studio Code and all the extensions that are available. It has become my preferred editor for almost everything (replacing Notepad++), except for when developing in Visual Studio.
Recently there is a new extension that was made available for working with Azure Event Grid. Typically when working with Azure Event Grid I use a tool called Postman to send test messages to my Azure Event Grid resource. But now with this latest extension you can use Visual Studio Code.
In this post I’ll walk through how to get started and use the Azure Event Grid extension for Visual Studio Code. Let’s get started.
Prerequisites
Before we can begin we need to make sure we have the following installed and setup:
- An Azure Subscription. If you don’t have an Azure Account, you can sign up for one today for free and receive $200 in credits by selecting "Create a Free Azure Account…" or selecting "View->Command Palette" and searching for "Azure: Create an Account"
- Install Visual Studio Code
- Visual Studio Code Extensions:
- Install extension Azure Tools for Visual Studio Code
- Install extension Azure Event Grid
Connecting to your Azure Subscription
First thing we need to do is connect to your Azure subscription. This will happen automatically when you go to the Azure tab in Visual Studio Code. You can also sign in from the Command palette and searching for “Azure: Login”.



Create an Event Grid Topic
Now that you’re signed in, let’s go ahead and create an Event Grid topic.
1. In the Event Grid Topics pane, click on the + button to create a new topic:

2. Then select your Azure Subscription to associate this topic with:

3. Now provide a topic name. I will use “VSCodeEventGridTopicDemo” for my demo:

4. Next select a resource group for your topic. I will use “RGVSCodeEventGridDemo” for my demo:

5. Select your location for the resources:

6. Done. In a few seconds your Azure Event Grid will be created and displayed in Visual Studio Code:


You can login to your Azure Subscription and see everything we just created. Keep your Azure Subscription loaded in the browser as we’ll use it for the next section.

Create Event Grid Subscription
Now that we have an Event Grid Topic setup we need to create a subscription to receive the events we send it.
1. Here I will create a new Azure Function app:

2. Now create a new Event Grid Trigger function and after it’s created click on the Add Event Grid subscription link:

3. Fill in the details relating to the Azure Event Grid Topic we created earlier and then press the Create button:

Your Event Grid Topic now has an Event Grid Subscription and is ready to test!
Generating Mock Events
Apart from managing your Event Grids resources in Visual Studio Code, you can also generate and send mock events which is great for testing purposes. Instead of using Postman to do this, I find the Event Grid Extension better and mocking and sending events. So let’s get started now mocking some events.
1. To generate a mocked event, right click on your Event Grid Subscription in Visual Studio Code and select Create Mock Event Generator:

2. A new file will be created with all the details for generating mocked events for this subscription. The pattern property is defined with regex patterns for generating random data. You will noticed I changed the data section pattern value with regex pattern to generate the mocked data for my event:

3. At the top of the event generator file will be two links: Send Events and Preview Events. The actions do exactly as they say and are what you want to use when generating your mocked events.

4. If we click on Preview Events, another file is created with a preview of mocked event data to be sent. Notice the different values between the events. This is from the regex logic defined in the event generator. This can be customized to generate data appropriate for your needs.

5. Now click on Send Events link at the top of the event generator file and go to your Azure Portal where you previously defined your Azure Function for your Event Grid Topic, and you will see in the logs your mocked events:

As you can see the Azure Event Grid extension for Visual Studio Code is very powerful and is a handy tool to use in your Azure development.
Enjoy!
Reference
Create your free Azure account
Azure Event Grid Overview
Azure Event Grid Documentation
Introduction to Azure serverless with Azure Functions, Logic Apps and Azure Event Grid
Like this:
Like Loading...