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
+56-20Lines changed: 56 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,63 +1,87 @@
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. You can see the existing code for the function and update it on this page.
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.":::
An event grid topic provides a user-defined endpoint that you post your events to.
60
+
An Event Grid topic provides a user-defined endpoint that you post your events to.
37
61
38
-
1.Sign in to [Azure portal](https://portal.azure.com/).
39
-
2.Select **All services** on the left navigational menu, search for **Event Grid**, and select **Event Grid Topics**.
62
+
1.On a new tab of the web browser window, sign in to [Azure portal](https://portal.azure.com/).
63
+
2.In the search bar at the topic, search for **Event Grid Topics**, and select **Event Grid Topics**.
40
64
41
-
:::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.
65
+
:::image type="content" source="./media/custom-event-to-function/select-event-grid-topics.png" alt-text="Image showing the selection of Event Grid topics.":::
66
+
3. On the **Event Grid Topics** page, select **+ Create** on the command bar.
43
67
44
-
:::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.":::
68
+
:::image type="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.":::
45
69
4. On the **Create Topic** page, follow these steps:
46
70
1. Select your **Azure subscription**.
47
71
2. Select the same **resource group** from the previous steps.
48
72
3. Provide a unique **name** for the custom topic. The topic name must be unique because it's represented by a DNS entry. Don't use the name shown in the image. Instead, create your own name - it must be between 3-50 characters and contain only values a-z, A-Z, 0-9, and "-".
49
-
4. Select a **location** for the event grid topic.
73
+
4. Select a **location** for the Event Grid topic.
50
74
5. Select **Review + create**.
51
75
52
76
:::image type="content" source="./media/custom-event-to-function/create-custom-topic.png" alt-text="Image showing the Create Topic page.":::
53
77
1. On the **Review + create** page, review settings and select **Create**.
54
-
5. After the custom topic has been created, select **Go to resource** link to see the following Event Grid Topic page for the topic you created.
78
+
5. After the custom topic has been created, select **Go to resource** link to see the following Event Grid topic page for the topic you created.
55
79
56
80
:::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.":::
57
81
58
82
## Subscribe to custom topic
59
83
60
-
You subscribe to an event grid topic to tell Event Grid which events you want to track, and where to send the events.
84
+
You subscribe to an Event Grid topic to tell Event Grid which events you want to track, and where to send the events.
61
85
62
86
1. Now, on the **Event Grid Topic** page for your custom topic, select **+ Event Subscription** on the toolbar.
63
87
@@ -89,15 +113,24 @@ The first example uses Azure CLI. It gets the URL and key for the custom topic,
89
113
1. In the Azure portal, select **Cloud Shell**. Select **Bash** in the top-left corner of the Cloud Shell window.
1. Set the `topicname` and `resourcegroupname` variables that will be used in the commands.
117
+
118
+
```azurecli
119
+
topicname="TOPICNAME"
120
+
```
121
+
122
+
```azurecli
123
+
resourcegroupname="RESOURCEGROUPNAME"
124
+
```
92
125
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
126
94
127
```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
131
99
132
```azurecli
100
-
key=$(az eventgrid topic key list --name <topic name> -g <resource group name> --query "key1" --output tsv)
0 commit comments