question

SoniScariah-7343 avatar image
0 Votes"
SoniScariah-7343 asked MayankBargali-MSFT edited

Unable to send custom event using EventGrid output binding from Azure Function


Using Azure Function (NodeJS), was able to successfully send an event using EventGrid as output being, to an an Event Grid configured with input schema of type EventGridSchema,

However, errors are logged, when attempt of send a custom event is made using similar approach to another Event Grid configured with input schema of type CustomEventSchema.

Error logged is:
(Failed, Id=6b155f7d-0751-450a-9c6d-11aae4ac77c8, Duration=15171ms)This resource is configured for 'CustomInputEvent' schema and requires 'subject' property to be set. Report '03680905-5f77-45ab-97ee-817002d5536b:2:9/2/2021 1:04:27 PM (UTC)' to our forums for assistance or raise a support ticket.

The message being set to the output binding variable is as below. Even though the topic is configured to accept custom event with the following mapping
"requestId" -> "id" , "remediationId" -> "subject" and the fields "eventType" and "dataVersion" set to default values, I was forced to provide the fields in the response message (without with errors were returned).

context.bindings.responseMessage = {
id: "id",
subject: "subject",
eventType: "eventType",
dataVersion: 1,
data: {
remediationId: "remediationId",
requestId: "requestId",
status: "status"
}
};

The corresponding bindings JSON snippet is pasted below

{
"type": "eventGrid",
"name": "responseMessage",
"topicEndpointUri": "RESPONSE_TOPIC_EP",
"topicKeySetting": "RESPONSE_TOPIC_KEY",
"direction": "out"
}

Please let me know if custom events are not supported by EventGrid when used as output binding. If so, is there a specific format that needs to be used to send the data, which can help resolve the error returned.

A related observation, was that the actual Event sending over the output binding, seems to happen after the function execution is completed, and there seems to be no way to wait for the sending to be complete, and then signal the end of function execution. Please advice is there is any way to achieve this.

azure-functions
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@SoniScariah-7343 As per the EvengGrid Output binding code currently it is supported EventGridEvent.
Unfortunately, you cannot use custom events currently. If your json object does not have any of the fields as per the EventGridEvent you should observe below error:
129426-image.png

The workaround will be using Event Grid REST API in your azure function to the send the event.

Update:
This is not currently supported and you can file an issue to support this with EventGrid Output binding.


image.png (16.6 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MayankBargali-MSFT

The issue that you have included in your response seems to be not related to this, and it mentions, updating the .NET API to be able to access the "data" part of an EventGridEvent, using generic type, rather than having to working with key-value pairs, from within HTTP triggered Azure function (EventGrid triggering HTTP Azure Function), where as in my case, its about Azure Function, sending events to Event Grid by using output bindings

Any reason why using EventGrid as output binding does not support Custom Events, when it is possible to use the SDK and push custom events to the same Event Grid from within Azure Function. The documentation does not seems to mention this limitation. Should not this be either documented as a limitation or a known bug.

0 Votes 0 ·

@SoniScariah-7343 My bad the github docs calls out for the different issue. The test that I have performed and the source code that I have shared for EventGrid Output binding is only supported for EventGridEvent. I have already reached out to my team and I do agree with you that right now the document doesnot specifically calls it out in the output binding document. I will update the document once I have confirmation from the team and will update the document accordingly.

0 Votes 0 ·

@MayankBargali-MSFT

Thanks for the update.

Can you also help clarify the observation made regarding the output binding , that the actual event sending (when it matches the EventGridEvent) format, happens after the Azure Function has completed its execution. There appears to be no way to await for the function, to wait until the event has been successfully delivered using the output binding. Is this expected and if so, can you please guide me to the appropriate documentation.

I agree using the SDK to send the events can be used as workaround in this case as well.

0 Votes 0 ·