Reputation:
I’m noticing a behavior with AWS Lambda where an SNS message triggers invocation to Lambda function (that’s subscribed to the SNS Topic) more than once at the same exact timestamp, a few milliseconds apart (there are no errors/timeouts in processing).
Updating the Concurrency to “Reserve Concurrency” => 1, https://jmp.sh/LqpWOPI prevents this from happening, but doing so would affect the scalability of this Async Lambda function.
Any thoughts on why this could be happening and how to handle it to avoid duplicate processing?
Upvotes: 2
Views: 1452
Reputation: 1730
According to the Lambda - Invoke AWS documentation, asynchronously triggered Lambda functions are guaranteed to be invoked at least once.
If you use the Event (asynchronous) invocation option, the function will be invoked at least once in response to an event and the function must be idempotent to handle this.
This is similar to the SQS at-least-once delivery of messages, in that you are guaranteed to get it one time, but may also get it a few additional times.
If you don't want to reduce your concurrency limit to 1, you'll have to make your Lambda function idempotent so it can handle multiple invocations gracefully.
Upvotes: 1