Does Event Grid output binding support . I want to send out the 'CloudEventV10' event triggered the function?

Anonymous
2024-03-10T21:11:38.07+00:00

I'm using python v2, your official documentation (Added below). Aside from that it's not working and not correct, i managed to edit it. but i'm struggling to how to send out the event in a 'CloudEventV10' schema? Is it supported? if it is how can i configure it?

import logging
import azure.functions as func
import datetime
@app.function_name(name="eventgrid_output")
@app.route(route="eventgrid_output")
@app.event_grid_output(
    arg_name="outputEvent",
    topic_endpoint_uri="MyEventGridTopicUriSetting",
    topic_key_setting="MyEventGridTopicKeySetting")
def eventgrid_output(eventGridEvent: func.EventGridEvent, 
         outputEvent: func.Out[func.EventGridOutputEvent]) -> None:
    logging.log("eventGridEvent: ", eventGridEvent)
    outputEvent.set(
        func.EventGridOutputEvent(
            id="test-id",
            data={"tag1": "value1", "tag2": "value2"},
            subject="test-subject",
            event_type="test-event-1",
            event_time=datetime.datetime.utcnow(),
            data_version="1.0")) 
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,284 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
316 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,146 Reputation points
    2024-03-11T19:02:33.2066667+00:00

    Thanks for posting your question in Microsoft Q&A.

    #1 The code snippet is incorrect which uses route instead of event_grid_trigger and missing few references. I see a solution with modified code snippet is provided in this discussion (let me know if any issues) and doc issue: https://github.com/MicrosoftDocs/azure-docs/issues/120627 was opened to address this. I already submitted PR for review and the changes will be merged soon. Sorry for the inconvenience caused by this issue.

    #2 Event Grid extension for Azure Functions supports CloudEvents v1.0 schema (for C#). However, SDK for Python still doesn't have a model for CloudEvents and only EventGridOutputEvent (don't think it support CloudEvents). There is an open item: CloudEvents schema in Python functions for this and I am reaching out to our product team and will update it. Please track this item for the latest.

    I hope this helps and let me know if any questions.


    If you found the answer to your question helpful, please take a moment to mark it as Yes for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.