Quickstart: Route Blob storage events to web endpoint with the Azure portal

Azure Event Grid is an eventing service for the cloud. In this article, you use the Azure portal to create a Blob storage account, subscribe to events for that blob storage, and trigger an event to view the result. Typically, you send events to an endpoint that processes the event data and takes actions. However, to simplify this article, you send the events to a web app that collects and displays the messages.

If you don't have an Azure subscription, create a free account before you begin.

When you're finished, you see that the event data has been sent to the web app.

View results

Create a storage account

  1. Sign in to Azure portal.

  2. To create a Blob storage, select Create a resource.

    Create a resource

  3. Select for Storage to filter the available options, and select Storage account - blob, file, table, queue.

    Select storage

  4. To subscribe to events, create either a general-purpose v2 storage account or a Blob storage account. For more information, see Create a storage account.

    Start steps

Create a message endpoint

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.

  1. Select Deploy to Azure to deploy the solution to your subscription. In the Azure portal, provide values for the parameters.

  2. The deployment may take a few minutes to complete. After the deployment has succeeded, view your web app to make sure it's running. In a web browser, navigate to: https://<your-site-name>.azurewebsites.net

  3. You see the site but no events have been posted to it yet.

    View new site

Enable Event Grid resource provider

If you haven't previously used Event Grid in your Azure subscription, you may need to register the Event Grid resource provider.

In the Azure portal:

  1. Select Subscriptions.
  2. Select the subscription you're using for Event Grid.
  3. Under Settings, select Resource providers.
  4. Find Microsoft.EventGrid.
  5. If not registered, select Register.

It may take a moment for the registration to finish. Select Refresh to update the status. When Status is Registered, you're ready to continue.

Subscribe to the Blob storage

You subscribe to a topic to tell Event Grid which events you want to track, and where to send the events.

  1. In the portal, select your blob storage and select Events.

    Select events

  2. To send events to your viewer app, use a web hook for the endpoint. Select More Options, and Web Hook.

    Select web hook

  3. The event subscription is prefilled with values for your Blob storage. For the web hook endpoint, provide the URL of your web app and add api/updates to the home page URL. Give your subscription a name. When done, select Create.

    Select logs

  4. 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.

    View subscription event

Now, let's trigger an event to see how Event Grid distributes the message to your endpoint.

Send an event 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.

  1. For your Blob storage, select Blobs.

    Select blobs

  2. Select + Container. Give you container a name, and use any access level.

    Add container

  3. Select your new container.

    Select container

  4. To upload a file, select Upload.

    Select upload

  5. Browse to your test file and upload it.

  6. 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.

     "topic": "/subscriptions/{subscription-id}/resourceGroups/eventgroup/providers/Microsoft.Storage/storageAccounts/demoblob0625",
     "subject": "/blobServices/default/containers/eventcontainer/blobs/testfile.txt",
     "eventType": "Microsoft.Storage.BlobCreated",
     "eventTime": "2018-06-25T22:50:41.1823131Z",
     "id": "89a2f9da-c01e-00bb-13d6-0c599506e4e3",
     "data": {
       "api": "PutBlockList",
       "clientRequestId": "41341a9b-e977-4a91-9000-c64125039047",
       "requestId": "89a2f9da-c01e-00bb-13d6-0c5995000000",
       "eTag": "0x8D5DAEE13C8F9ED",
       "contentType": "text/plain",
       "contentLength": 4,
       "blobType": "BlockBlob",
       "url": "https://demoblob0625.blob.core.windows.net/eventcontainer/testfile.txt",
       "sequencer": "00000000000000000000000000001C24000000000004712b",
       "storageDiagnostics": {
         "batchId": "ef633252-32fd-464b-8f5a-0d10d68885e6"
     "dataVersion": "",
     "metadataVersion": "1"

Clean up resources

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.

Next steps

Now that you know how to create custom topics and event subscriptions, learn more about what Event Grid can help you do: