5

While I understand EventBridge will retry sending an event - through a rule - to a target, such as an API Destination, is there any way to read the receiving API's response code and any returned messages for the respective invocation (i.e., the original invocation and any subsequent retries)?

What I have: an event triggered from a Step Function, which is sent to EventBridge. The Event is filtered by an "app ID" rule, and invokes an external API (note: note one of the pre-integrated API's available via AWS). I am able to receive the API call using webhook.site, however, I would like to use the response data inside the sending web app. As such, I need to be able to call the latest API response on demand - and would like to keep trying failed attempts periodically for a pre-set period of approx 14 days.

raffibag
  • 119
  • 1
  • 10

2 Answers2

3

In 2022 (at re:invent) AWS introduced Amazon EventBridge Pipes. Pipes have an optional enrichment step. You can use Amazon EventBridge API Destination for such an enrichment step. Used together with Pipes (as opposed to an EventBridge rule target) the API Destination will be called synchronously (per default) and its response will be transported to the target of the pipe.

So what you could do is something like:

your event -> EventBus -> "app ID" rule -> SQS (rule target and pipe source) -> API Destination (enrichment) -> SQS (pipe target)

You can then consume the responses from the API calls via the SQS queue at the end of that flow.

Andreas Grimm
  • 195
  • 1
  • 7
  • This is a really nice solution! Thanks for sharing. Unfortunately you also don't get any insights if the API Destination does not work. – Tobias Stangl Mar 08 '23 at 07:33
2

No there is no such way, unless you implement a custom solution for that yourself. For example, have EB rule trigger a lambda function, which is going to save event and its metadata in a dynamodb. Then you can manage invocations of your other target yourself.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Thanks @Marcin... So is it possible to invoke the target directly, without a rule? The issue I'm having is that the event gets sent to the EventBus, which is then routed to the target (the API Destination) via the rule... It's (seemingly) because of the rule that I'm unable to record the API Destination's response. If there's a way to send the event to the target directly, I can see this solution working. – raffibag Mar 13 '22 at 00:32
  • @raffibag Your lambda function would be the target, which then would invoke your API destination. Since you program the lambda, you can do what ever you want. – Marcin Mar 14 '22 at 00:30
  • Thanks again, @Marcin, but I still don't quite follow. The issue with your solution, as I understand how API Destinations work, is that the Lambda would have to invoke the API Destination by sending an Event to EventBridge, which leads us back to the original issue: events sent to API Destinations via EventBridge return no results. See: https://aws.amazon.com/blogs/compute/using-api-destinations-with-amazon-eventbridge/ If there *is* a way to invoke the API dest directly, that would be the solution for me. If so, can you please link to the documentation showing how to invoke directly? – raffibag Mar 14 '22 at 16:21
  • Also to clarify: when mentioning "API Destination," I'm referring, specifically, to the EventBridge destination created with `createApiDestination` (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EventBridge.html#createApiDestination-property)... not a generic "API destination." – raffibag Mar 14 '22 at 16:36
  • @raffibag In that case, there is no such way. You have to re-architect your application, as what you want to do is not possible. – Marcin Mar 14 '22 at 23:49
  • 2
    I'll accept this as the answer, as it appears to be the case that there is no way to read the response of an API Destination using EventBridge (which seems crazy to me). Was able to create a custom lambda to handle the outbound api call logic. – raffibag Mar 15 '22 at 16:37