You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/event-grid/custom-event-to-function.md
+80-22Lines changed: 80 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,63 +1,105 @@
1
1
---
2
2
title: 'Quickstart: Send custom events to Azure Function - Event Grid'
3
3
description: 'Quickstart: Use Azure Event Grid and Azure CLI or portal to publish a topic, and subscribe to that event. An Azure Function is used for the endpoint.'
4
-
ms.date: 09/28/2021
4
+
ms.date: 11/02/2022
5
5
ms.topic: quickstart
6
6
ms.custom: mode-other, devx-track-azurecli
7
7
ms.devlang: azurecli
8
8
---
9
9
10
10
# Quickstart: Route custom events to an Azure Function with Event Grid
11
11
12
-
Azure Event Grid is an eventing service for the cloud. Azure Functions is one of the supported event handlers. In this article, you use the Azure portal to create a custom topic, subscribe to the custom topic, and trigger the event to view the result. You send the events to an Azure Function.
12
+
[Azure Event Grid](overview.md) is an eventing service for the cloud. Azure Functions is one of the [supported event handlers](event-handlers.md). In this article, you use the Azure portal to create a custom topic, subscribe to the custom topic, and trigger the event to view the result. You send the events to an Azure Function.
1. Sign in to the [Azure portal](https://portal.azure.com).
19
+
1. On the left navigational menu, select **All services**.
20
+
1. Select **Compute** in the list of **Categories**.
21
+
1. Hover (not select) the mouse over **Function App**, and select **Create**.
22
+
23
+
:::image type="content" source="./media/custom-event-to-function/create-function-app-link.png" lightbox="./media/custom-event-to-function/create-function-app-link.png" alt-text="Screenshot showing the select of Create link for a Function App.":::
24
+
1. On the **Basics** page of the **Create Function App** wizard, follow these steps:
25
+
1. Select your **Azure subscription** in which you want to create the function app.
26
+
1. Create a new **resource group** or select an existing resource group.
27
+
1. Specify a **name** for the function app.
28
+
1. Select **.NET** for **Runtime stack**.
29
+
1. Select the **region** closest to you.
30
+
1. Select **Next: Hosting** at the bottom of the page.
31
+
32
+
:::image type="content" source="./media/custom-event-to-function/create-function-app-page.png" alt-text="Screenshot showing the Basics tab of the Create Function App page.":::
33
+
1. On the **Hosting** page, create a new storage account or select an existing storage account to be associated with the function app, and then select **Review + create** at the bottom of the page.
34
+
35
+
:::image type="content" source="./media/custom-event-to-function/create-function-app-hosting-page.png" alt-text="Screenshot showing the Hosting tab of the Create Function App page.":::
36
+
1. On the **Review + create** page, review settings, and select **Create** at the bottom of the page to create the function app.
37
+
1. Once the deployment is successful, select **Go to resource** to navigate to the home page for the function app.
38
+
39
+
## Create a function
17
40
Before subscribing to the custom topic, create a function to handle the events.
18
41
19
-
1. Create a function app using instructions from [Create a function app](../azure-functions/functions-get-started.md).
20
42
1. On the **Function App** page, select **Functions** on the left menu.
21
-
1. Select **+Create** on the toolbar to create a function.
43
+
1. Select **+ Create** on the toolbar to create a function.
44
+
45
+
:::image type="content" source="./media/custom-event-to-function/create-function-link.png" alt-text="Screenshot showing the selection of Create function link.":::
46
+
22
47
1. On the **Create Function** page, follow these steps:
23
48
1. This step is optional. For **Development environment**, select the development environment that you want to use to work with the function code.
24
-
1. Select **Azure Event Grid Trigger** in the **Select a template** section.
25
-
1.Enter a name for the function. In this example, it's **HandleEventsFunc**.
49
+
1. Select **Azure Event Grid Trigger** in the **Select a template** section. Use the scroll bar right to the list to scroll down if needed.
50
+
1.In the **Template details** section in the bottom pane, enter a name for the function. In this example, it's **HandleEventsFunc**.
4.Use the **Code + Test** page to see the existing code for the function and update it.
53
+
4.On the **Function** page for the **HandleEventsFunc**, select **Code + Test** on the left navigational menu.
29
54
30
55
:::image type="content" source="./media/custom-event-to-function/function-code-test-menu.png" alt-text="Image showing the selection Code + Test menu for an Azure function.":::
:::imagetype="content"source="./media/custom-event-to-function/function-updated-code.png"alt-text="Screenshot showing the Code + Test view of an Azure function with the updated code.":::
:::image type="content" source="./media/custom-event-to-function/select-event-grid-topics.png" alt-text="Image showing the selection of Event Grid Topics.":::
42
-
3. On the **Event Grid Topics** page, select **+ Add** on the toolbar.
83
+
:::imagetype="content"source="./media/custom-event-to-function/select-event-grid-topics.png"alt-text="Image showing the selection of Event Grid topics.":::
:::image type="content" source="./media/custom-event-to-function/add-event-grid-topic-button.png" alt-text="Image showing the Create button to create an event grid topic.":::
86
+
:::imagetype="content"source="./media/custom-event-to-function/add-event-grid-topic-button.png"alt-text="Screenshot showing the Create button to create an Event Grid topic.":::
3. Provideaunique**name**forthecustomtopic. Thetopicnamemustbeuniquebecauseit's represented by a DNS entry. Don'tusethenameshownintheimage. Instead, createyourownname-itmustbebetween3-50charactersandcontainonlyvaluesa-z, A-Z, 0-9, and"-".
49
-
4. Select a **location** for the event grid topic.
91
+
4. Selecta**location**fortheEventGridtopic.
50
92
5. Select**Review+create**.
51
93
52
94
:::imagetype="content"source="./media/custom-event-to-function/create-custom-topic.png"alt-text="Image showing the Create Topic page.":::
:::image type="content" source="./media/custom-event-to-function/event-grid-topic-home-page.png" alt-text="Image showing the home page for your Event Grid custom topic.":::
98
+
:::imagetype="content"source="./media/custom-event-to-function/event-grid-topic-home-page.png"lightbox="./media/custom-event-to-function/event-grid-topic-home-page.png"alt-text="Image showing the home page for your Event Grid custom topic.":::
57
99
58
100
## Subscribe to custom topic
59
101
60
-
You subscribe to an event grid topic to tell Event Grid which events you want to track, and where to send the events.
1. Set the `topicname` and `resourcegroupname` variables that will be used in the commands.
135
+
136
+
Replace `TOPICNAME` with the name of your Event Grid topic.
137
+
138
+
```azurecli
139
+
topicname="TOPICNAME"
140
+
```
141
+
142
+
Replace `RESOURCEGROUPNAME` with the name of the Azure resource group that contains the Event Grid topic.
143
+
144
+
```azurecli
145
+
resourcegroupname="RESOURCEGROUPNAME"
146
+
```
92
147
1. Run the following command to get the **endpoint** for the topic: After you copy and paste the command, update the **topic name** and **resource group name** before you run the command.
93
148
94
149
```azurecli
95
-
endpoint=$(az eventgrid topic show --name <topic name> -g <resource group name> --query "endpoint" --output tsv)
2. Run the following command to get the **key** for the custom topic: After you copy and paste the command, update the **topic name** and **resource group** name before you run the command.
98
153
99
154
```azurecli
100
-
key=$(az eventgrid topic key list --name <topic name> -g <resource group name> --query "key1" --output tsv)
@@ -160,7 +218,7 @@ The second example uses PowerShell to perform similar steps.
160
218
### Verify that function received the event
161
219
You've triggered the event, and Event Grid sent the message to the endpoint you configured when subscribing. Navigate to your Event Grid triggered function and open the logs. You should see a copy of the data payload of the event in the logs. If you don'tmakesureyouopenthelogswindowfirst, orhitreconnect, andthentrysendingatesteventagain.
162
220
163
-
:::image type="content" source="./media/custom-event-to-function/successful-function.png" alt-text="Image showing the Monitor view of the Azure function with a log.":::
221
+
:::imagetype="content"source="./media/custom-event-to-function/successful-function.png"lightbox="./media/custom-event-to-function/successful-function.png"alt-text="Image showing the Monitor view of the Azure function with a log.":::
164
222
165
223
## Clean up resources
166
224
Ifyouplantocontinueworkingwiththisevent, don't clean up the resources created in this article. Otherwise, delete the resources you created in this article.
0 commit comments