title | description | ms.date | ms.topic | ms.custom |
---|---|---|---|---|
Use Azure Event Grid to send Blob storage events to web endpoint - portal |
Quickstart: Use Azure Event Grid and Azure portal to create Blob storage account, and subscribe its events. Send the events to a Webhook. |
07/01/2021 |
quickstart |
mode-ui |
Event Grid is a fully managed service that enables you to easily manage events across many different Azure services and applications. It simplifies building event-driven and serverless applications. For an overview of the service, see Event Grid overview.
In this article, you use the Azure portal to do the following tasks:
- Create a Blob storage account.
- Subscribe to events for that blob storage.
- Trigger an event by uploading a file to the blob storage.
- View the result in a handler web app. Typically, you send events to an endpoint that processes the event data and takes actions. To keep it simple, you send events to a web app that collects and displays the messages.
[!INCLUDE quickstarts-free-trial-note.md]
When you're finished, you see that the event data has been sent to the web app.
-
Sign in to Azure portal.
-
To create a Blob storage, select Create a resource.
-
In the Search, enter Storage account, and select Storage account from the result list.
:::image type="content" source="./media/blob-event-quickstart-portal/search-storage-account.png" alt-text="Screenshot showing the search for Storage account on the Create a resource page.":::
-
On the Storage account page, select Create to start creating the storage account. To subscribe to events, create either a general-purpose v2 storage account or a Blob storage account.
-
On the Create storage account page, do the following steps:
-
Select your Azure subscription.
-
For Resource group, create a new resource group or select an existing one.
-
Enter the name for your storage account.
-
Select the Region in which you want the storage account to be created.
-
For Redundancy, select Locally-redundant storage (LRS) from the drop-down list.
-
Select Review + create.
:::image type="content" source="./media/blob-event-quickstart-portal/create-storage-account-page.png" alt-text="Screenshot showing the Create a storage account page.":::
-
On the Review + create page, review the settings, and select Create.
[!NOTE] Only storage accounts of kind StorageV2 (general purpose v2) and BlobStorage support event integration. Storage (general purpose v1) does not support integration with Event Grid.
-
Before subscribing to the events for the Blob storage, let's create the endpoint for the event message. Typically, the endpoint takes actions based on the event data. To simplify this quickstart, you deploy a pre-built web app that displays the event messages. The deployed solution includes an App Service plan, an App Service web app, and source code from GitHub.
-
Select Deploy to Azure to deploy the solution to your subscription.
-
On the Custom deployment page, do the following steps:
-
For Resource group, select the resource group that you created when creating the storage account. It will be easier for you to clean up after you are done with the tutorial by deleting the resource group.
-
For Site Name, enter a name for the web app.
-
For Hosting plan name, enter a name for the App Service plan to use for hosting the web app.
-
Select Review + create.
:::image type="content" source="./media/blob-event-quickstart-portal/template-deploy-parameters.png" alt-text="Screenshot showing the Custom deployment page.":::
-
-
On the Review + create page, select Create.
-
The deployment may take a few minutes to complete. Select Alerts (bell icon) in the portal, and then select Go to resource group.
-
On the Resource group page, in the list of resources, select the web app that you created. You also see the App Service plan and the storage account in this list.
-
On the App Service page for your web app, select the URL to navigate to the web site. The URL should be in this format:
https://<your-site-name>.azurewebsites.net
. -
Confirm that you see the site but no events have been posted to it yet.
[!INCLUDE event-grid-register-provider-portal.md]
You subscribe to a topic to tell Event Grid which events you want to track, and where to send the events.
-
In the portal, navigate to your Azure Storage account that you created earlier. On the left menu, select All resources and select your storage account.
-
On the Storage account page, select Events on the left menu.
-
Select More Options, and Web Hook. You are sending events to your viewer app using a web hook for the endpoint.
-
On the Create Event Subscription page, do the following steps:
-
Enter a name for the event subscription.
-
Enter a name for the system topic. To learn about system topics, see Overview of system topics.
-
Select Web Hook for Endpoint type.
-
-
For Endpoint, click Select an endpoint, and enter the URL of your web app and add
api/updates
to the home page URL (for example:https://spegridsite.azurewebsites.net/api/updates
), and then select Confirm Selection. -
Now, on the Create Event Subscription page, select Create to create the event subscription.
-
View your web app again, and notice that a subscription validation event has been sent to it. Select the eye icon to expand the event data. Event Grid sends the validation event so the endpoint can verify that it wants to receive event data. The web app includes code to validate the subscription.
Now, let's trigger an event to see how Event Grid distributes the message to your endpoint.
You trigger an event for the Blob storage by uploading a file. The file doesn't need any specific content. The articles assumes you have a file named testfile.txt, but you can use any file.
-
In the Azure portal, navigate to your Blob storage account, and select Containers on the let menu.
-
Select + Container. Give you container a name, and use any access level, and select Create.
-
Select your new container.
-
To upload a file, select Upload. On the Upload blob page, browse and select a file that you want to upload for testing, and then select Upload on that page.
-
Browse to your test file and upload it.
-
You've triggered the event, and Event Grid sent the message to the endpoint you configured when subscribing. The message is in the JSON format and it contains an array with one or more events. In the following example, the JSON message contains an array with one event. View your web app and notice that a blob created event was received.
If you plan to continue working with this event, don't clean up the resources created in this article. Otherwise, delete the resources you created in this article.
Select the resource group, and select Delete resource group.
Now that you know how to create custom topics and event subscriptions, learn more about what Event Grid can help you do: