How to make service idempotent to eventbridge

76 Views Asked by At

I have an eventbridge rule which is configured to trigger a lambda which calls an api of my app at some cron intervals (let's say every 1 hour). Eventbridge guarantees "at least once" delivery but I want that my app register the event "only once".

Does the "id" field of eventbridge event structure change for multiple events of a single invocation? (See: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events-structure.html)

I mean if for 1 invocation, 2 events are generated at 01:00:00.000 and 01:00:00.001 (hh:mm:ss) then will the "id" field remain same or different for both. If it will be different is there any way to know if those 2 are duplicate events at my app?

1

There are 1 best solutions below

2
Michael Gasch On

You might want to consider switching to https://aws.amazon.com/eventbridge/scheduler/?nc1=h_ls which gives you additional context attributes to detect duplicate invocations: https://docs.aws.amazon.com/scheduler/latest/UserGuide/managing-schedule-context-attributes.html (<aws.scheduler.attempt-number>). Retried attempts will have different <aws.scheduler.execution-id>.

Note that Lambda invocation is async which may lead to additional invocations from the Lambda side with the same event. So you also need to check for the same <aws.scheduler.execution-id> to detect duplicates.