Request (+/Response from) Azure Function with Event Grid

Patrick Schneider 86 Reputation points
2021-03-15T15:32:00.85+00:00

Hello,

i would like to implement a low-delay (near-realtime) control loop with an Azure Functions App and the Event Grid Trigger/(Output-)Binding.

77795-image.png

The microcontroller sends temporary data and expect revised values.

My preferred programming language was python. I created a Azure Function App and an event grid topic + subscription. The Azure function app contains one azure function with the following (from the quickstart manipulated) files.

function.json:
77855-image.png

init.py:
77796-image.png

Based on my understanding of Azure Functions and Event Grid, the Event Grid Topic Endpoint is the bidirectional interface to Trigger (+ Input in "data" Attribute) the function and return the response.

In the following i would like to send an "event grid trigger" - event with a test script and print the response.

77873-image.png

The execution fails (Error 401), but i don´t know how to fix it. Or whether the basic structure is expedient or has structural errors.

I hope somebody can help me.

With best regards
Patrick

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,644 questions
Azure Event Grid
Azure Event Grid
An Azure event routing service designed for high availability, consistent performance, and dynamic scale.
350 questions
0 comments No comments
{count} votes

Accepted answer
  1. MayankBargali-MSFT 69,991 Reputation points
    2021-03-16T04:20:22.487+00:00

    Hi @Patrick Schneider

    Event grid is used for event based architecture/event programming. The events are pushed at the event grid topics (i.e. through event sources) and there are event handlers that are triggered based on the configuration specified in your event grid subscription.

    In your scenario your application is sending events to event grid topic and the function is configured as the endpoint of your event grid subscription for that topic. In your function app code, you are again sending the event to the event grid topic (not sure if it is the same or a new topic).
    Your setup cannot work for bi-directional communication as event grids are not meant for this. If you still want to use, then when you are sending the events to the event grid topic from functions then you need to create an event grid subscription (endpoint configured as your webhook endpoint) on that topic where you are sending the event from the function app.

    Alternatively, you can refer to this for a comparison of messaging services.

    To answer your query why you are getting 401 error when sending an event to event grid topic. If you look into your below code you are not passing the header for authentication. You need to pass header with "aeg-sas-key": "youreventgridtopickeys". You can refer to post to custom topic for more details.

    78027-image.png

    Feel free to reach out to me if you have any queries or concerns.

    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful