Event Grid payload exception for Function EventGridTrigger
See original GitHub issueAzure Functions are throwing an EventGridTrigger exception.
Repro steps
- Create a Function with an EventGridTrigger attribute on a CloudEvent parameter. Doesn’t matter if it’s static or async.
[FunctionName("eventgridtriggertest")] public static void Run(ILogger log, [EventGridTrigger] CloudEvent e)
- Trigger the Function with an appropriate event.
In the Portal you can do this by creating an Event Grid Topic or System Topic from Storage Account > Events and then create a subscription with the following filter:
Subject begins with: /blobServices/default/containers/{containerName} Filter to event types: Blob Created Event Schema: EventGridSchema
You can simulate this locally by hitting the function at this url: POST http://localhost:7071/runtime/webhooks/eventgrid?functionname=myFunctionName Headers: aeg-event-type: Notification Content-Type: application/json
Body:
Here is an example of an event payload (taken from https://docs.microsoft.com/en-au/azure/event-grid/event-schema-blob-storage?tabs=event-grid-event-schema#microsoftstorageblobcreated-event and also here https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-grid-trigger?tabs=csharp%2Cbash#manually-post-the-request)
[{ "topic": "/subscriptions/{subscriptionId}/resourceGroups/Storage/providers/Microsoft.Storage/storageAccounts/{storageAccount}", "subject": "/blobServices/default/containers/{containerName}/blobs/new-file.txt", "eventType": "Microsoft.Storage.BlobCreated", "eventTime": "2021-06-26T18:41:00.9584103Z", "id": "831e1650-001e-001b-66ab-eeb76e069631", "data": { "api": "PutBlockList", "clientRequestId": "6d79dbfb-0e37-4fc4-981f-442c9ca65760", "requestId": "831e1650-001e-001b-66ab-eeb76e000000", "eTag": "\"0x8D4BCC2E4835CD0\"", "contentType": "text/plain", "contentLength": 524288, "blobType": "BlockBlob", "url": "https://{storageAccount}.blob.core.windows.net/{containerName}/new-file.txt", "sequencer": "00000000000004420000000000028963", "storageDiagnostics": { "batchId": "b68529f3-68cd-4744-baa4-3c0498ec19f0" } }, "dataVersion": "", "metadataVersion": "1" }]
Note this has camel case parameters eventType, eventTime, dataVersion, metadataVersion. You can make these lower case to mitigate the error. Then you get an error that it is also missing the following fields (values are my guesses):
"specversion":"1.0", "source":"EventGrid", "type":"EventGrid",
Once all these errors have been corrected the Function will run correctly.
Expected behaviour
An Event Grid Topic or Event Grid System Topic with a subscription to a Storage event should trigger a Function without error. (This may apply to other events as well as storage events.)
Actual behaviour
When running in the portal, the Function fails with the following error:
'Invalid character in extension attribute name: ‘T’. CloudEvent attribute names must consist of lower-case letters (‘a’ to ‘z’) or digits (‘0’ to ‘9’) from the ASCII character set. (Parameter ‘name’)`
This can also be replicated by running the Function locally, which breaks with an exception:
System.ArgumentException
HResult=0x80070057
Message=Invalid character in extension attribute name: ‘T’. CloudEvent attribute names must consist of lower-case letters (‘a’ to ‘z’) or digits (‘0’ to ‘9’) from the ASCII character set.
Source=Azure.Core
StackTrace:
at Azure.Messaging.CloudEventExtensionAttributes2.ValidateAttribute(String name, Object value) at Azure.Messaging.CloudEventExtensionAttributes
2.Add(TKey key, TValue value)
at Azure.Messaging.CloudEventConverter.DeserializeCloudEvent(JsonElement element, Boolean skipValidation)
at Azure.Messaging.CloudEvent.Parse(BinaryData json, Boolean skipValidation)
at Microsoft.Azure.WebJobs.Extensions.EventGrid.EventGridExtensionConfigProvider.<>c.<Initialize>b__6_5(JToken jobject)
at Microsoft.Azure.WebJobs.Host.Bindings.PatternMatcher.<>c__DisplayClass8_0`2.<New>b__0(Object src, Attribute attr, ValueBindingContext ctx) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Bindings\PatternMatcher.cs:line 58
Known workarounds
Setting the subscription endpoint to a Logic App instead can get around this issue.
Related information
Provide any related information
- Functions version 3
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top GitHub Comments
Hi @stuartdotnet, Thank you for your feedback! We will investigate this further and update you with the findings.
@alrod, sorry I missed your reply! I have been out of office for some time. I will try to create a bug in the other repository. /christoph