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
+53-23Lines changed: 53 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,7 +68,7 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
68
68
69
69
Don't choose a project folder that's already part of a workspace.
70
70
71
-
1. At the prompts, provide the following information:
71
+
1. At the prompts, provide the following information:
72
72
73
73
::: zone pivot="programming-language-csharp"
74
74
|Prompt|Action|
@@ -79,7 +79,7 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
79
79
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
80
80
|**Provide a namespace**| Enter `My.Functions`. |
81
81
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
82
-
|**Select subscription**| Select your subscription.|
82
+
|**Select subscription**| Select your subscription, if needed.|
83
83
|**Select a storage account**| Use Azurite emulator for local storage. |
84
84
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
85
85
|**Select how you would like to open your project**| Select `Open in current window`. |
@@ -88,16 +88,16 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
88
88
|Prompt|Action|
89
89
|--|--|
90
90
|**Select a language**| Select `Python`. |
91
-
|**Select a Python programming model**| Select `V1`|
91
+
|**Select a Python programming model**| Select `Model V2`|
92
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. |
93
-
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
93
+
|**Select a template for your project's first function**| Select `Blob trigger`. (The event-based template isn't yet available.)|
94
94
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
95
+
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
95
96
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
96
-
|**Select subscription**| Select your subscription.|
97
+
|**Select subscription**| Select your subscription, if needed.|
97
98
|**Select a storage account**| Use Azurite emulator for local storage. |
98
-
|**The path within your storage account that the trigger will monitor**| Accept the default value `samples-workitems`. |
99
99
|**Select how you would like to open your project**| Select `Open in current window`. |
100
-
::: zone-end
100
+
::: zone-end
101
101
::: zone pivot="programming-language-java"
102
102
|Prompt|Action|
103
103
|--|--|
@@ -112,16 +112,16 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
112
112
|**Select how you would like to open your project**| Select `Open in current window`. |
113
113
114
114
An HTTP triggered function (`HttpExample`) is created for you. You won't use this function and must instead create a new function.
115
-
::: zone-end
116
-
::: zone pivot="programming-language-typescript"
115
+
::: zone-end
116
+
::: zone pivot="programming-language-typescript"
117
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
122
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
123
123
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
124
-
|**Select subscription**| Select your subscription.|
124
+
|**Select subscription**| Select your subscription, if needed.|
125
125
|**Select a storage account**| Use Azurite emulator for local storage. |
126
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`. |
@@ -134,7 +134,7 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
134
134
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
135
135
|**Provide a function name**| Enter `eventGridBlobTrigger`. |
136
136
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
137
-
|**Select subscription**| Select your subscription.|
137
+
|**Select subscription**| Select your subscription, if needed.|
138
138
|**Select a storage account**| Use Azurite emulator for local storage. |
139
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`. |
@@ -146,7 +146,7 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
146
146
|**Select a template for your project's first function**| Select `Azure Blob Storage trigger (using Event Grid)`. |
147
147
|**Provide a function name**| Enter `EventGridBlobTrigger`. |
148
148
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
149
-
|**Select subscription**| Select your subscription.|
149
+
|**Select subscription**| Select your subscription, if needed.|
150
150
|**Select a storage account**| Use Azurite emulator for local storage. |
151
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`. |
@@ -169,8 +169,29 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
169
169
170
170
You now have a function that can be triggered by events in a Blob Storage container.
171
171
172
-
## (Optional) Review the code
172
+
::: zone pivot="programming-language-python"
173
+
## Update the trigger source
173
174
175
+
You first need to switch the trigger source from the default Blob trigger source (container polling) to an event subscription source.
176
+
177
+
1. Open the function_app.py project file and you see a definition for the `EventGridBlobTrigger` function with the `blob_trigger` decorator applied.
178
+
179
+
1. Update the decorator by adding `source = "EventGrid"`. Your function should now look something like this:
logging.info(f"Python blob trigger function processed blob"
186
+
f"Name: {myblob.name}"
187
+
f"Blob Size: {myblob.length} bytes")
188
+
```
189
+
190
+
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.
191
+
::: zone-end
192
+
::: zone pivot="programming-language-csharp,programming-language-typescript,programming-language-powershell,programming-language-java,programming-language-javascript"
193
+
## (Optional) Review the code
194
+
::: zone-end
174
195
::: zone pivot="programming-language-csharp"
175
196
Open the generated `EventGridBlobTrigger.cs`fileand you see a definition for an `EventGridBlobTrigger` function that looks something like this:
176
197
@@ -195,7 +216,7 @@ Open the generated `EventGridBlobTrigger.java` file and you see a definition for
195
216
196
217
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
218
::: zone-end
198
-
::: zone pivot="programming-language-python,programming-language-powershell"
219
+
::: zone pivot="programming-language-powershell"
199
220
In the `EventGridBlobTrigger` folder, open the `function.json`fileand find a binding definition like this with a `type` of `blobTrigger`and a `source` of `EventGrid`:
@@ -348,12 +369,12 @@ Now both the Functions host and the trigger are sharing the same storage account
348
369
349
370
To create an event subscription, you need to provide Event Grid with the URL of the specific endpoint to report Blob Storage events. This _blob extension_ URLis composed of these parts:
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:
359
380
@@ -371,7 +392,7 @@ The blob extension access key is designed to make it more difficult for others t
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.
395
+
In this example, replace `<FUNCTION_APP_NAME>`with the name of your function app,and`<BLOB_EXTENSION_KEY>`with the value you got from the portal. If you used a different name for your function, replace `EventGridBlobTrigger`with that function name.
375
396
376
397
You can now use this endpoint URL to create an event subscription.
377
398
@@ -383,7 +404,7 @@ An event subscription, powered by Azure Event Grid, raises events based on chang
383
404
384
405
1. Sign in to the [Azure portal](https://portal.azure.com) and make a note of the **Resource group**for your storage account. You create your other resources in the same group to make it easier to clean up resources when you're done.
385
406
386
-
1. select the **Events** option from the left menu.
407
+
1. Select the **Events** option from the left menu.
|**Enable subject filtering**|*Enabled*| Enables filtering on which blobs can trigger the function. |
428
+
|**Subject Begins With**|**`/blobServices/default/containers/<CONTAINER_NAME>/blobs/<BLOB_PREFIX>`**| Replace `<CONTAINER_NAME`and`<BLOB_PREFIX>`with values you choose. This sets the subscription to trigger only for blobs that start with`BLOB_PREFIX`and are in the `CONTAINER_NAME` container. |
429
+
|**Subject Ends With**|*.txt*| Ensures that the function will only be triggered by blobs ending with`.txt`. |
430
+
431
+
For more information on filtering to specific blobs, see [Event Filtering for Azure Event Hubs](../event-grid/event-filtering.md).
402
432
403
-
1. Select **Create** to create the event subscription.
433
+
7. Select **Create** to create the event subscription.
404
434
405
435
## Upload a file to the container
406
436
@@ -433,6 +463,6 @@ Now that you uploaded a file to the **samples-workitems** container, the functio
433
463
434
464
## Next steps
435
465
436
-
+ [Working with blobs](storage-considerations.md#working-with-blobs)
466
+
- [Working with blobs](storage-considerations.md#working-with-blobs)
437
467
- [Automate resizing uploaded images using Event Grid](../event-grid/resize-images-on-storage-blob-upload-event.md)
438
468
- [Event Grid trigger for Azure Functions](./functions-bindings-event-grid.md)
0 commit comments