How to send events from Event Grid basic to Event Grid namespace topics
This article describes how to forward events from event subscriptions created in resources like topics, system topics, domains, and partner topics to Event Grid namespaces.
Overview
Event Grid basic supports Event Grid Namespace topic as the endpoint type. When creating an event subscription to an Event Grid topic, system topic, domain, or partner topic, you can select an Event Grid namespace topic as the endpoint for handling events.
Namespace topic as a destination in Event Grid basic event subscriptions helps you with transitioning to Event Grid namespaces without modifying your existing workflow. Event Grid namespaces provide new and interesting capabilities that you might be interested to use in your solutions. If you're currently using Event Grid basic resources like topics, system topics, domains, and partner topics you only need to create a new event subscription in your current topic and select Event Grid namespace topic as a handler destination.
This article covers an example scenario where you forward Azure Storage events to an Event Grid namespace. Here are the high-level steps:
- Create a system topic for the Azure storage account and enable managed identity for the system topic.
- Assign the system topic's managed identity to the Event Grid Data Sender role on the destination Event Grid namespace.
- Create an event subscription to the system topic with the Event Grid namespace as the event handler, and use the managed identity for event delivery.
Prerequisites
- Create an Event Grid namespace resource by following instructions from Create, view, and manage namespaces.
- Create an Event Grid namespace topic by following instructions from Create, view, and manage namespace topics.
- Create an Event Grid event subscription in a namespace topic by following instructions from Create, view, and manage event subscriptions in namespace topics. This step is optional, but it's useful for testing the scenario.
- Create an Azure storage account by following instructions from create a storage account.
Create a system topic and enable managed identity for the storage account
If you have an existing system topic for the storage account, navigate to the system topic page. If you don't have one, create a system topic. Then, enable managed identity for the storage account.
Navigate to Azure portal.
In the search bar, search for Event Grid System Topics, and select it from the search results.
On the Event Grid System Topics page, select + Create.
On the Create Event Grid System Topic page, follow these steps:
For Topic Types, select Storage Accounts.
For Subscription, select the Azure subscription where you want to create the system topic.
For Resource Group, select the resource group for the system topic.
For Resource, select the Azure storage resource for which you want to create the system topic.
In the System Topic Details section, for Name, enter a name for the topic.
Select Review + create at the bottom of the page.
On the Review + create page, review settings, and select Create.
After the deployment is successful, select Go to resource to navigate to the Event Grid System Topic page for the system topic you created.
Enable managed identity for the system topic
Now, enable managed identity for the system topic you created. For this example, let's create a system-assigned managed identity for the system topic.
On the Event Grid System Topic page, select Identity under Settings on the left navigation menu.
On the Identity page, select On for Status.
Select Save on the command bar.
On the confirmation pop-up window, select Yes to confirm the creation of the managed identity.
After the managed identity is created, you see the object (principal) ID for the identity.
Keep the System Topic page open in the current tab of your web browser.
Grant the identity permission to send events to the namespace
In the last step, you created a system-assigned managed identity for your storage account's system topic. In this step, you grant the identity the permission to send events to the target or destination namespace.
Launch a new tab or a window of the web browser. Navigate to your Event Grid namespace in the Azure portal.
Select Access control (IAM) on the left menu.
Select Add and then select Add role assignment.
On the Role page, search for and select Event Grid Data Sender role, and then select Next.
On the Members page, for Assign access to, select Managed identity, and then choose + Select members.
On the Select managed identities page, follow these steps:
For Subscription, select the Azure subscription where the managed identity is created.
For Managed identity, select Event Grid System Topic.
For Select, type the name of your system topic.
In the search results, select the managed identity. The managed identity's name is same as the system topic's name.
On the Members page, select Next.
On the Review + assign page, review settings, and select Review + assign at the bottom of the page.
Create an event subscription to the storage system topic
Now, you're ready to create an event subscription to the system topic for the source storage account using the namespace as an endpoint.
On the System Topic page for the system topic, select Overview on the left menu if it's not already selected.
Select + Event Subscription on the command bar.
On the Create Event Subscription page, follow these steps:
For Name, enter the name for an event subscription.
For Event Schema, select the event schema as Cloud Events Schema v1.0. It's the only schema type that the Event Grid Namespace Topic destination supports.
For Filter to Event Types, select types of events you want to subscribe to.
For Endpoint type, select Event Grid Namespace Topic.
Select Configure an endpoint.
On the Select Event Grid Namespace Topic page, follow these steps:
- For Subscription, select the Azure subscription, resource group, and the namespace that has the namespace topic.
- For Event Grid namespace topic, select the namespace topic.
- Select Confirm selection at the bottom of the page.
Now, on the Create Event Subscription page, for Managed identity type, select System assigned.
Select Create at the bottom of the page.
To test the scenario, create a container in the Azure blob storage and upload a file to it. Verify that the event handler or endpoint for your namespace topic receives the blob created event.
When you upload a blob to a container in the Azure storage, here's what happens:
- Azure Blob Storage sends a Blob Created event to your blob storage's system topic.
- The event is forwarded to your namespace topic as it's the event handler or endpoint for the system topic.
- The endpoint for the subscription to the namespace topic receives the forwarded event.
Related content
See the following articles: