Azure Event Grid is the glue that lets you connect disparate Azure services, and when you want to kick off an Azure Logic App or Azure Functions workflow in response to something happening elsewhere in Azure, Event Grid is your go-to.
Let’s see it in action. Imagine you’ve got an Azure Storage Account and you want to automatically process any new .jpg files uploaded to a specific container. We can use Event Grid to trigger a Logic App that will, say, resize the image.
First, we need to create an Event Subscription. In the Azure portal, navigate to your Event Grid topic (or create one if you don’t have one yet). Click "Create Event Subscription."
For the "Topic type," select "Azure Subscriptions" if you want to react to events across your entire subscription, or choose a specific resource like "Storage Accounts." For our example, we’ll select "Storage Accounts" and then pick our specific storage account.
Next, we need to define the "Event types" we’re interested in. For new blobs in a storage account, we’ll select Microsoft.Storage.BlobCreated.
Now, for the "Endpoint type," this is where we tell Event Grid what to trigger. We’ll choose "Azure Function" or "Logic App." Let’s go with Logic App. You’ll then select the specific Logic App you want to invoke.
The "Endpoint" field will auto-populate with the webhook URL for your chosen Logic App. Event Grid will send a POST request to this URL when the event occurs.
Under "Filters," you can get granular. For our .jpg example, we want to filter by the blob name. We’ll add a filter where the "Subject" (which for blob events is typically the blob’s full path) "ends with" .jpg. You can also filter by resource group, resource type, and even custom event data.
Once created, when a new .jpg file is uploaded to the specified container in our storage account, Event Grid will detect the Microsoft.Storage.BlobCreated event, see that the subject matches our .jpg filter, and then send a payload to the Logic App’s webhook.
The Logic App receives this payload, which contains details about the event, including the URL of the newly created blob. We can then use this information in subsequent actions within the Logic App, such as fetching the blob content and passing it to an image processing action.
This pattern is incredibly powerful for building event-driven architectures. Instead of constantly polling a storage account for new files, services can simply react when something happens. This is far more efficient and scalable.
The "Subject" field in the event payload is crucial. For Storage Account events, it’s formatted as /subscriptions/{subscription-id}/resourceGroups/{resource-group}/providers/Microsoft.Storage/storageAccounts/{storage-account-name}/blobServices/default/containers/{container-name}/blobs/{blob-name}. Understanding this structure allows for precise filtering.
The real magic is how Event Grid decouples services. The storage account doesn’t need to know about the Logic App, and the Logic App doesn’t need to know how to poll the storage account. Event Grid handles the reliable delivery of events between them.
The next step is to explore custom event topics, allowing you to emit your own events from applications and services to trigger workflows.