I'm using Python V2 model event grid trigger and output binding. I'm using microsoft example code provided. I'm deploying using git action and local-exe. I tried deploying just the trigger and it successfully got deployed and was able to see it on the azure portal. When I tried deploying with output to write to a custom topic. In git actions it successfully deployed without any errors but i dont see it on azure portal and stopped being triggered.

my requiremnets.txt just has azure-functions

import logging
import azure.functions as func
import datetime


@app.function_name(name="eventGridTrigger")
@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"))

to be able to see it and to get triggered and forward the event to the custom topic

1

There are 1 best solutions below

6
Pravallika KV On

I have followed MSDOC and implemented output binding with the below code:

Code Snippet:

app = func.FunctionApp()

@app.function_name(name="eventgridout")
@app.event_grid_trigger(arg_name="eventGridEvent")
@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.info("eventGridEvent: %s", eventGridEvent)

    outputEvent.set(
        func.EventGridOutputEvent(
            id="123",
            data={"tag1": "value1", "tag2": "value2"},
            subject="test-subject",
            event_type="test-event-1",
            event_time=datetime.datetime.utcnow(),
            data_version="1.0"))

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "MyEventGridTopicUriSetting":"<Topic_Endpoint_Uri>",
    "MyEventGridTopicKeySetting":"<Topic_access_key>"
  }
}
  • Created an Event Grid Topic and configured the subscription with Function app endpoint.

enter image description here

  • Add the settings in Environment Variables=>Application Settings in the function app:
1. MyEventGridTopicUriSetting="<Topic_Endpoint_Uri>"
2. MyEventGridTopicKeySetting="<Topic_access_key>"

enter image description here

  • Deployed the Function to Azure:

enter image description here

enter image description here

  • Able to trigger the function successfully:

enter image description here

enter image description here

  • Configured EventHub to send the events to Storage Account Queue.

enter image description here