question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for returning HTTP status code from EventGrid-triggered function

See original GitHub issue

According to the docs on delivery and retries for EventGrid, the returned HTTP status code can have a significant (and useful!) effect on the retry policy. It would be quite useful for a function using the EventGrid binding to be able to report such status codes, yet the documentation only showcases void returning implementations.

How would a function, for example, report a 503 Service Unavailable for a downstream processor so that the Retry after 30 seconds or more applies automatically?

  • Function App version: 2.0
  • C# web app.

NOTE: trying to return Task<IActionResult> or Task<HttpResponseMessage> results in an error like:

The '[NAME]' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method '[NAME]'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type [TYPE]&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).

(where [NAME] is the name of the function and [TYPE] is either HttpResponseMessage or IActionResult).

NOTE: for IActionResult, I did add a call to Configure to add MVC:

        public void Configure(IWebJobsBuilder builder)
        {
            ...
            builder.Services.AddMvcCore();
        }

Repro steps

Provide the steps required to reproduce the problem:

  1. Create an Azure Functions app in VS
  2. Select an EventGrid trigger function and replace the code with:
        [FunctionName("return-status-code")]
        public static Task<HttpResponseMessage> RunAsync([EventGridTrigger] EventGridEvent e)
            => Task.FromResult(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable));
  1. F5 and see the error:
[10/6/2020 18:46:02] Microsoft.Azure.WebJobs.Host: Error indexing method 'return-status-code'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter '$return' to type HttpResponseMessage&. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).
[10/6/2020 18:46:02] Error indexing method 'return-status-code'

Expected behavior

Things just work, EventGrid gets the status code from the response and uses that to apply the retry policy as documented.

Known workarounds

Use a webhook subscription/function instead of an EventTrigger function 😦

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:19
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
fabiocavcommented, Jun 24, 2020

This is a feature request. The EventGrid binding does not support results today and will handle responses based on its own logic.

For control over the HTTP response, the recommended approach is what you’ve mentioned above, using an HTTP triggered function.

4reactions
kirmakcommented, Sep 16, 2020

It would be good to have a way to control dead-lettering and retry behavior from EventGrid-triggered function. Thanks! Official documentation saying that

It is strongly recommended that you use an Event Grid Trigger when triggering an Azure Function with Event Grid.

https://docs.microsoft.com/en-us/azure/event-grid/receive-events

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support for returning HTTP status code from EventGrid ...
According to the docs on delivery and retries for EventGrid, the returned HTTP status code can have a significant (and useful!)
Read more >
How to properly return status/error codes from an Azure ...
I'm trying to wrap my head around how to manage controlled and uncontrolled results/failures in Azure Functions triggered by Event Grid events.
Read more >
Azure Event Grid bindings for Azure Functions
Run a function when an Event Grid event is dispatched, Trigger. Sends an Event Grid event, Output binding. Control the returned HTTP status...
Read more >
Returning HTTP Status Codes from Azure Functions
When creating HTTP-triggered Azure Functions there are a number of ways to indicate results back to the calling client. Returning HTTP Status ......
Read more >
Middleware for Azure Functions
HTTP Trigger : This trigger allows you to invoke your Azure Function using an HTTP request. · Timer Trigger · Blob Trigger ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found