using python v2 azure event grid output binding and keeps complaining about function.json

79 Views Asked by At

I'm literally using microsoft azure official documentation for event grid output binding. and this is there code. I'm using python V2 which doesn't rely on function.json, however i keep getting errors on function.json, why?

import logging
import azure.functions as func
import datetime

app = func.FunctionApp()

@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")) 

This is the exception i keep getting!

Exception: FunctionLoadError: cannot load the test function: the following parameters are declared in Python but not in function.json: {'eventGridEvent'}

Easily runing since it;s on their official page

1

There are 1 best solutions below

5
Pavan On

I'm literally using microsoft azure official documentation for event grid output binding. and this is there code. I'm using python V2 which doesn't rely on function.json, however i keep getting errors on function.json,

Initially I am also getting same errors by followed the DOC eventgrid output binding.

  • I have added the trigger to the given code. it works fine. check below:

function code:

import azure.functions as func
import datetime
import logging

app = func.FunctionApp()

@app.function_name(name="eventgrid_out")
@app.event_grid_trigger(arg_name="eventGridEvent")
@app.event_grid_output(
    arg_name="outputEvent",
    topic_endpoint_uri="your-endpoint",
    topic_key_setting="your-topic key")
def eventgrid_output(eventGridEvent: func.EventGridEvent,
        outputEvent: func.Out[func.EventGridOutputEvent]) -> None:

    logging.info("eventGridEvent: %s", 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"))

The above code executed successfully. check below:

Output:

enter image description here