question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Event Grid payload exception for Function EventGridTrigger

See original GitHub issue

Azure Functions are throwing an EventGridTrigger exception.

Repro steps

  1. 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)

  1. 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.CloudEventExtensionAttributes2.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:closed
  • Created 2 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
v-bbalaiagarcommented, Dec 7, 2021

Hi @stuartdotnet, Thank you for your feedback! We will investigate this further and update you with the findings.

0reactions
froeschelcommented, May 5, 2022

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Azure Event Grid trigger for Azure Functions
The trigger uses an HTTP request that can't reach the function app without a gateway into the virtual network.
Read more >
How to properly return status/error codes from an Azure ...
1 Answer 1 ... To Q1: Currently version of the EventGridTrigger function doesn't have a specific exception object to handle for its wrapper...
Read more >
Event Grid message delivery and retry - Azure
Describes how Azure Event Grid delivers events and how it handles undelivered messages.
Read more >
Debugging Azure Function Event Grid Triggers Locally
Here we learn how to debug Azure Functions Event Grid triggers locally using Visual Studio and Postman.
Read more >
Exception handling and retries · Issue #32
I have been testing the EventGridTrigger and have a question/clarification. When a function fails it is logged, but not retried from Event ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found