Skip to content

Commit 58e8d79

Browse files
committed
Event Grid - ARM quickstart
1 parent 5516610 commit 58e8d79

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
title: 'Send Blob storage events to web endpoint - template'
3+
description: Use Azure Event Grid and an Azure Resource Manager template to create Blob storage account, and subscribe its events. Send the events to a Webhook.'
4+
services: event-grid
5+
keywords:
6+
author: spelluru
7+
ms.author: spelluru
8+
ms.date: 01/15/2020
9+
ms.topic: quickstart
10+
ms.service: event-grid
11+
---
12+
# Route Blob storage events to web endpoint by using Azure Resource Manager template
13+
Azure Event Grid is an eventing service for the cloud. In this article, you use an **Azure Resource Manager template** 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.
14+
15+
[Resource Manager template](../azure-resource-manager/templates/overview.md) is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. If you want to learn more about developing Resource Manager templates, see [Resource Manager documentation](/azure/azure-resource-manager/).
16+
17+
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/) before you begin.
18+
19+
## Prerequisites
20+
### Create a message endpoint
21+
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](https://github.com/Azure-Samples/azure-event-grid-viewer) that displays the event messages. The deployed solution includes an App Service plan, an App Service web app, and source code from GitHub.
22+
23+
1. Select **Deploy to Azure** to deploy the solution to your subscription. In the Azure portal, provide values for the parameters.
24+
25+
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure-Samples%2Fazure-event-grid-viewer%2Fmaster%2Fazuredeploy.json" target="_blank"><img src="https://azuredeploy.net/deploybutton.png"/></a>
26+
27+
1. 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:
28+
`https://<your-site-name>.azurewebsites.net`
29+
30+
1. You see the site but no events have been posted to it yet.
31+
32+
![View new site](./media/blob-event-quickstart-portal/view-site.png)
33+
34+
35+
## Create a storage account with an Event Grid subscription
36+
The template used in this quickstart is from [Azure Quickstart templates](https://github.com/Azure/azure-quickstart-templates/tree/master/101-event-grid-subscription-and-storage).
37+
38+
[!code-json[<Azure Resource Manager template create Blob strage Event Grid subscription>](~/quickstart-templates/101-event-grid-subscription-and-storage/azuredeploy.json)]
39+
40+
Two Azure resources are defined in the template:
41+
42+
* **Microsoft.Storage/storageAccounts**: create an Azure Storage account.
43+
* **"Microsoft.Storage/storageAccounts/providers/eventSubscriptions**: create an Azure Event Grid subscription for the storage account.
44+
45+
You can find more Azure Key Vault template samples [here](https://azure.microsoft.com/en-us/resources/templates/?resourceType=Microsoft.Eventgrid).
46+
47+
1. Select the following image to sign in to Azure and open a template. The template creates a key vault and a secret.
48+
49+
<a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-event-grid-subscription-and-storage%2Fazuredeploy.json"><img src="./media/quick-create-template/deploy-to-azure.png" alt="deploy to azure"/></a>
50+
2. Select or enter the following values.
51+
52+
- **Subscription**: select an Azure subscription.
53+
- **Resource group**: select the resource group that contains the web application that you deployed earlier.
54+
- **Location**: select a location. For example, **Central US**.
55+
- **Endpoint**: provide the URL of your web app and add `api/updates` to the home page URL.
56+
3. Select **Purchase** to deploy the template.
57+
58+
The Azure portal is used to deploy the template. In addition to the Azure portal, you can also use the Azure PowerShell, Azure CLI, and REST API. To learn other deployment methods, see [Deploy templates](../azure-resource-manager/templates/deploy-powershell.md).
59+
60+
## Validate the deployment
61+
1. 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.
62+
63+
![View subscription event](./media/blob-event-quickstart-portal/view-subscription-event.png)
64+
65+
Now, let's trigger an event to see how Event Grid distributes the message to your endpoint.
66+
67+
## Send an event to your endpoint
68+
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.
69+
70+
When you upload the file to the Azure Blob storage, Event Grid sends a 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.
71+
72+
```json
73+
[{
74+
"topic": "/subscriptions/{subscription-id}/resourceGroups/eventgroup/providers/Microsoft.Storage/storageAccounts/demoblob0625",
75+
"subject": "/blobServices/default/containers/eventcontainer/blobs/testfile.txt",
76+
"eventType": "Microsoft.Storage.BlobCreated",
77+
"eventTime": "2018-06-25T22:50:41.1823131Z",
78+
"id": "0000000000-0000-0000-0000-000000000000",
79+
"data": {
80+
"api": "PutBlockList",
81+
"clientRequestId": "000000000-0000-0000-0000-000000000000",
82+
"requestId": "000000000-0000-0000-0000-000000000000",
83+
"eTag": "0x8D5DAEE13C8F9ED",
84+
"contentType": "text/plain",
85+
"contentLength": 4,
86+
"blobType": "BlockBlob",
87+
"url": "https://demoblob0625.blob.core.windows.net/eventcontainer/testfile.txt",
88+
"sequencer": "00000000000000000000000000001C24000000000004712b",
89+
"storageDiagnostics": {
90+
"batchId": "ef633252-32fd-464b-8f5a-0d10d68885e6"
91+
}
92+
},
93+
"dataVersion": "",
94+
"metadataVersion": "1"
95+
}]
96+
```
97+
98+
You see that the event data has been sent to the web app.
99+
100+
![View results](./media/blob-event-quickstart-portal/view-results.png)
101+
102+
103+
104+
## Clean up resources
105+
When no longer needed, [delete the resource group](../azure-resource-manager/management/delete-resource-group.md?tabs=azure-portal#delete-resource-group
106+
).
107+
108+
## Next steps
109+
For more information about Azure Resource Manager templates, see the following articles:
110+
111+
- [Azure Resource Manager documentation](/azure/azure-resource-manager)
112+
- [Define resources in Azure Resource Manager templates](/azure/templates/)
113+
- [Azure Quickstart templates](https://azure.microsoft.com/resources/templates/)

articles/event-grid/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
href: ../storage/blobs/storage-blob-event-quickstart-powershell.md?toc=%2fazure%2fevent-grid%2ftoc.json
2020
- name: Portal
2121
href: blob-event-quickstart-portal.md
22+
- name: Template
23+
displayName: arm, resource manager template
24+
href: blob-event-quickstart-template.md
2225
- name: Custom events
2326
items:
2427
- name: Azure CLI

0 commit comments

Comments
 (0)