Support for returning HTTP status code from EventGrid-triggered function
See original GitHub issueAccording 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 toConfigure
to add MVC:
public void Configure(IWebJobsBuilder builder)
{
...
builder.Services.AddMvcCore();
}
Repro steps
Provide the steps required to reproduce the problem:
- Create an Azure Functions app in VS
- 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));
- 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:
- Created 3 years ago
- Reactions:19
- Comments:11 (3 by maintainers)
Top GitHub Comments
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.
It would be good to have a way to control dead-lettering and retry behavior from EventGrid-triggered function. Thanks! Official documentation saying that
https://docs.microsoft.com/en-us/azure/event-grid/receive-events