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/azure-functions/functions-event-grid-blob-trigger.md
+85-21Lines changed: 85 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: 'Tutorial: Trigger Azure Functions on blob containers using an event subs
3
3
description: This tutorial shows how to create a low-latency, event-driven trigger on an Azure Blob Storage container using an Event Grid event subscription.
#Customer intent: As an Azure Functions developer, I want learn how to create an event-based trigger on a Blob Storage container so that I can get a more rapid response to changes in the container.
9
9
---
@@ -34,7 +34,6 @@ This article creates a C# app that runs in isolated worker mode, which supports
34
34
35
35
> [!IMPORTANT]
36
36
> This tutorial has you use the [Flex Consumption plan](flex-consumption-plan.md), which is currently in preview. The Flex Consumption plan only supports the event-based version of the Blob Storage trigger.
37
-
> You can complete this tutorial using any other [hosting plan](functions-scale.md) for your function app.
38
37
39
38
## Prerequisites
40
39
@@ -63,11 +62,9 @@ This article creates a C# app that runs in isolated worker mode, which supports
63
62
64
63
When you create a Blob Storage trigger function using Visual Studio Code, you also create a new project. You need to edit the function to consume an event subscription as the source, rather than use the regular polled container.
65
64
66
-
1. In Visual Studio Code, open your function app.
65
+
1. In Visual Studio Code, press F1 to open the command palette, enter `Azure Functions: Create Function...`, and select **Create new project**.
67
66
68
-
1. Press F1 to open the command palette, enter `Azure Functions: Create Function...`, and select **Create new project**.
69
-
70
-
1. For your project workspace, select the directory location. Make sure that you either create a new folder or choose an empty folder for the project workspace.
67
+
1. For your project workspace, select a directory location. Make sure that you either create a new folder or choose an empty folder for the project workspace.
71
68
72
69
Don't choose a project folder that's already part of a workspace.
73
70
@@ -79,25 +76,26 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
79
76
|**Select a language**| Select `C#`. |
80
77
|**Select a .NET runtime**| Select `.NET 8.0 Isolated LTS`. |
81
78
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
82
-
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
79
+
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
83
80
|**Provide a namespace**| Enter `My.Functions`. |
84
81
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
85
82
|**Select subscription**| Select your subscription.|
86
83
|**Select a storage account**| Use Azurite emulator for local storage. |
87
-
|**This is the path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
84
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
88
85
|**Select how you would like to open your project**| Select `Open in current window`. |
89
86
::: zone-end
90
87
::: zone pivot="programming-language-python"
91
88
|Prompt|Action|
92
89
|--|--|
93
90
|**Select a language**| Select `Python`. |
91
+
|**Select a Python programming model**| Select `V1`|
94
92
|**Select a Python interpreter to create a virtual environment**| Select your preferred Python interpreter. If an option isn't shown, enter the full path to your Python binary. |
95
93
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
96
-
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
94
+
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
97
95
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
98
96
|**Select subscription**| Select your subscription.|
99
97
|**Select a storage account**| Use Azurite emulator for local storage. |
100
-
|**This is the path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
98
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
101
99
|**Select how you would like to open your project**| Select `Open in current window`. |
102
100
::: zone-end
103
101
::: zone pivot="programming-language-java"
@@ -106,24 +104,26 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
106
104
|**Select a language**| Select `Java`. |
107
105
|**Select a version of Java**| Select `Java 11` or `Java 8`, the Java version on which your functions run in Azure and that you've locally verified. |
108
106
|**Provide a group ID**| Select `com.function`. |
109
-
|**Provide an artifact ID**| Select `BlobTriggerEventGrid`. |
107
+
|**Provide an artifact ID**| Select `EventGridBlobTrigger` (or the default). |
110
108
|**Provide a version**| Select `1.0-SNAPSHOT`. |
111
109
|**Provide a package name**| Select `com.function`. |
112
-
|**Provide an app name**| Accept the generated name starting with `BlobTriggerEventGrid`. |
110
+
|**Provide an app name**| Accept the generated name starting with `EventGridBlobTrigger`. |
113
111
|**Select the build tool for Java project**| Select `Maven`. |
114
112
|**Select how you would like to open your project**| Select `Open in current window`. |
113
+
114
+
An HTTP triggered function (`HttpExample`) is created for you. You won't use this function and must instead create a new function.
115
115
::: zone-end
116
116
::: zone pivot="programming-language-typescript"
117
-
|Prompt|Action|
117
+
|Prompt|Action|
118
118
|--|--|
119
119
|**Select a language for your function project**| Select `TypeScript`. |
120
120
|**Select a TypeScript programming model**| Select `Model V4`. |
121
121
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
122
-
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
122
+
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
123
123
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
124
124
|**Select subscription**| Select your subscription.|
125
125
|**Select a storage account**| Use Azurite emulator for local storage. |
126
-
|**This is the path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
126
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
127
127
|**Select how you would like to open your project**| Select `Open in current window`. |
128
128
::: zone-end
129
129
::: zone pivot="programming-language-javascript"
@@ -132,26 +132,90 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
132
132
|**Select a language for your function project**| Select `JavaScript`. |
133
133
|**Select a JavaScript programming model**| Select `Model V4`. |
134
134
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
135
-
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
135
+
|**Provide a function name**| Enter `eventGridBlobTrigger`. |
136
136
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
137
137
|**Select subscription**| Select your subscription.|
138
138
|**Select a storage account**| Use Azurite emulator for local storage. |
139
-
|**This is the path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
139
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
140
140
|**Select how you would like to open your project**| Select `Open in current window`. |
141
141
::: zone-end
142
142
::: zone pivot="programming-language-powershell"
143
143
|Prompt|Action|
144
144
|--|--|
145
145
|**Select a language for your function project**| Select `PowerShell`. |
146
146
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
147
-
|**Provide a function name**| Enter `BlobTriggerEventGrid`. |
147
+
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
148
148
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
149
149
|**Select subscription**| Select your subscription.|
150
150
|**Select a storage account**| Use Azurite emulator for local storage. |
151
-
|**This is the path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
151
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
152
152
|**Select how you would like to open your project**| Select `Open in current window`. |
153
153
::: zone-end
154
154
155
+
::: zone pivot="programming-language-java"
156
+
4. In the command palette, enter `Azure Functions: Create Function...` and select `EventGridBlobTrigger`. If you don't see this templates, first select **Change template filter** > **All**.
157
+
158
+
5. At the prompts, provide the following information:
159
+
160
+
|Prompt|Action|
161
+
|--|--|
162
+
|**Provide a package name**| Select `com.function`. |
163
+
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
164
+
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
165
+
|**Select subscription**| Select your subscription.|
166
+
|**Select a storage account**| Use Azurite emulator for local storage. |
167
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
168
+
::: zone-end
169
+
170
+
You now have a function that can be triggered by events in a Blob Storage container.
171
+
172
+
## (Optional) Review the code
173
+
174
+
::: zone pivot="programming-language-csharp"
175
+
Open the generated `EventGridBlobTrigger.cs` file and you see a definition for an `EventGridBlobTrigger` function that looks something like this:
In this definition `Source = BlobTriggerSource.EventGrid` indicates that an event subscription to the blob container (in the example `PathValue`) is used as the source of the event that starts the trigger.
180
+
::: zone-end
181
+
::: zone pivot="programming-language-java"
182
+
Open the generated `EventGridBlobTrigger.java` file and you see a definition for an `EventGridBlobTrigger` function that looks something like this:
context.getLogger().info("Java Blob trigger function processed a blob. Name: "+ name +"\n Size: "+ content.length +" Bytes");
193
+
}
194
+
```
195
+
196
+
In this definition `source = EventGrid` indicates that an event subscription to the `samples-workitems` blob container is used as the source of the event that starts the trigger.
197
+
::: zone-end
198
+
::: zone pivot="programming-language-python,programming-language-powershell"
199
+
In the `EventGridBlobTrigger` folder, open the `function.json` file and find a binding definition like this with a `type` of `blobTrigger` and a `source` of `EventGrid`:
In this definition a `source` of `EventGrid` indicates that an event subscription to the `samples-workitems` blob container is used as the source of the event that starts the trigger.
211
+
::: zone-end
212
+
::: zone pivot="programming-language-typescript"
213
+
Open the generated `EventGridBlobTrigger.ts` file and you see a definition for a function that looks something like this:
In this definition a `source` of `EventGrid` indicates that an event subscription to the `samples-workitems` blob container is used as the source of the event that starts the trigger.
218
+
::: zone-end
155
219
156
220
## Upgrade the Storage extension
157
221
@@ -288,7 +352,7 @@ To create an event subscription, you need to provide Event Grid with the URL of
288
352
| --- | --- |
289
353
| Base function app URL |`https://<FUNCTION_APP_NAME>.azurewebsites.net`|
290
354
| Blob-specific path |`/runtime/webhooks/blobs`|
291
-
| Function query string |`?functionName=Host.Functions.BlobTriggerEventGrid`|
355
+
| Function query string |`?functionName=Host.Functions.EventGridBlobTrigger`|
The blob extension access key is designed to make it more difficult for others to access your blob extension endpoint. To determine your blob extension access key:
@@ -304,7 +368,7 @@ The blob extension access key is designed to make it more difficult for others t
304
368
1. Create a new endpoint URL for the Blob Storage trigger based on the following example:
In this example, replace `<FUNCTION_APP_NAME>` with the name of your function app and replace `<BLOB_EXTENSION_KEY>` with the value you got from the portal. If you used a different name for your function, you'll also need to change the `functionName` query string value to your function name.
0 commit comments