Skip to content

Commit 7d0c30f

Browse files
committed
event grid blob updates
1 parent 2df092e commit 7d0c30f

File tree

1 file changed

+85
-21
lines changed

1 file changed

+85
-21
lines changed

articles/azure-functions/functions-event-grid-blob-trigger.md

Lines changed: 85 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: 'Tutorial: Trigger Azure Functions on blob containers using an event subs
33
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.
44
ms.topic: tutorial
55
ms.custom: devx-track-extended-java, devx-track-js, devx-track-python, devx-track-ts
6-
ms.date: 05/20/2024
6+
ms.date: 11/09/2024
77
zone_pivot_groups: programming-languages-set-functions
88
#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.
99
---
@@ -34,7 +34,6 @@ This article creates a C# app that runs in isolated worker mode, which supports
3434

3535
> [!IMPORTANT]
3636
> 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.
3837
3938
## Prerequisites
4039

@@ -63,11 +62,9 @@ This article creates a C# app that runs in isolated worker mode, which supports
6362

6463
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.
6564

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**.
6766

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.
7168

7269
Don't choose a project folder that's already part of a workspace.
7370

@@ -79,25 +76,26 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
7976
|**Select a language**| Select `C#`. |
8077
|**Select a .NET runtime**| Select `.NET 8.0 Isolated LTS`. |
8178
|**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`. |
8380
|**Provide a namespace** | Enter `My.Functions`. |
8481
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
8582
|**Select subscription**| Select your subscription.|
8683
|**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`. |
8885
|**Select how you would like to open your project**| Select `Open in current window`. |
8986
::: zone-end
9087
::: zone pivot="programming-language-python"
9188
|Prompt|Action|
9289
|--|--|
9390
|**Select a language**| Select `Python`. |
91+
|**Select a Python programming model** | Select `V1` |
9492
|**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. |
9593
|**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`. |
9795
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
9896
|**Select subscription**| Select your subscription.|
9997
|**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`. |
10199
|**Select how you would like to open your project**| Select `Open in current window`. |
102100
::: zone-end
103101
::: zone pivot="programming-language-java"
@@ -106,24 +104,26 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
106104
|**Select a language**| Select `Java`. |
107105
|**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. |
108106
| **Provide a group ID** | Select `com.function`. |
109-
| **Provide an artifact ID** | Select `BlobTriggerEventGrid`. |
107+
| **Provide an artifact ID** | Select `EventGridBlobTrigger` (or the default). |
110108
| **Provide a version** | Select `1.0-SNAPSHOT`. |
111109
| **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`. |
113111
| **Select the build tool for Java project** | Select `Maven`. |
114112
|**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.
115115
::: zone-end
116116
::: zone pivot="programming-language-typescript"
117-
|Prompt|Action|
117+
|Prompt|Action|
118118
|--|--|
119119
|**Select a language for your function project**| Select `TypeScript`. |
120120
|**Select a TypeScript programming model**| Select `Model V4`. |
121121
|**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`. |
123123
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
124124
|**Select subscription**| Select your subscription.|
125125
|**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`. |
127127
|**Select how you would like to open your project**| Select `Open in current window`. |
128128
::: zone-end
129129
::: zone pivot="programming-language-javascript"
@@ -132,26 +132,90 @@ When you create a Blob Storage trigger function using Visual Studio Code, you al
132132
|**Select a language for your function project**| Select `JavaScript`. |
133133
|**Select a JavaScript programming model**| Select `Model V4`. |
134134
|**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`. |
136136
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
137137
|**Select subscription**| Select your subscription.|
138138
|**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`. |
140140
|**Select how you would like to open your project**| Select `Open in current window`. |
141141
::: zone-end
142142
::: zone pivot="programming-language-powershell"
143143
|Prompt|Action|
144144
|--|--|
145145
|**Select a language for your function project**| Select `PowerShell`. |
146146
|**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`. |
148148
|**Select setting from "local.settings.json"**| Select `Create new local app setting`. |
149149
|**Select subscription**| Select your subscription.|
150150
|**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`. |
152152
|**Select how you would like to open your project**| Select `Open in current window`. |
153153
::: zone-end
154154

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:
176+
177+
:::code language="csharp" source="~/functions-quickstart-templates/Functions.Templates/Templates/EventGridBlobTrigger-CSharp-Isolated-6.x/EventGridBlobTriggerCSharp.cs" range="17-23":::
178+
179+
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:
183+
184+
```java
185+
@FunctionName("EventGridBlobTrigger")
186+
@StorageAccount("<STORAGE_ACCOUNT>")
187+
public void run(
188+
@BlobTrigger(name = "content", source = "EventGrid", path = "samples-workitems/{name}", dataType = "binary") byte[] content,
189+
@BindingName("name") String name,
190+
final ExecutionContext context
191+
) {
192+
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`:
200+
201+
:::code language="json" source="~/functions-quickstart-templates/Functions.Templates/Templates/EventGridBlobTrigger-PowerShell/function.json" :::
202+
203+
The `path` indicates that the `samples-workitems` blob container is used as the source of the event that starts the trigger.
204+
::: zone-end
205+
::: zone pivot="programming-language-javascript"
206+
Open the generated `EventGridBlobTrigger.js` file and you see a definition for a function that looks something like this:
207+
208+
:::code language="javascript" source="~/azure-functions-nodejs-v4/js/src/functions/storageBlobTriggerEventGrid1.js" :::
209+
210+
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:
214+
215+
:::code language="typescript" source="~/azure-functions-nodejs-v4/ts/src/functions/storageBlobTriggerEventGrid1.ts" :::
216+
217+
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
155219

156220
## Upgrade the Storage extension
157221

@@ -288,7 +352,7 @@ To create an event subscription, you need to provide Event Grid with the URL of
288352
| --- | --- |
289353
| Base function app URL | `https://<FUNCTION_APP_NAME>.azurewebsites.net` |
290354
| Blob-specific path | `/runtime/webhooks/blobs` |
291-
| Function query string | `?functionName=Host.Functions.BlobTriggerEventGrid` |
355+
| Function query string | `?functionName=Host.Functions.EventGridBlobTrigger` |
292356
| Blob extension access key | `&code=<BLOB_EXTENSION_KEY>` |
293357

294358
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
304368
1. Create a new endpoint URL for the Blob Storage trigger based on the following example:
305369

306370
```http
307-
https://<FUNCTION_APP_NAME>.azurewebsites.net/runtime/webhooks/blobs?functionName=Host.Functions.BlobTriggerEventGrid&code=<BLOB_EXTENSION_KEY>
371+
https://<FUNCTION_APP_NAME>.azurewebsites.net/runtime/webhooks/blobs?functionName=Host.Functions.EventGridBlobTrigger&code=<BLOB_EXTENSION_KEY>
308372
```
309373
310374
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

Comments
 (0)