How do I prevent duplicate Lambda function invocations?
Last updated: 2021-11-18
My AWS Lambda function keeps receiving more than one invocation request for a single event. How do I prevent my Lambda function from invoking multiple times from the same event?
Short description
To help prevent duplicate Lambda function invocations, do the following based on the invocation type that you're using.
Note: For synchronous invocations, the clients and AWS services that invoke a Lambda function are responsible for performing retries. For asynchronous invocations, Lambda automatically retries on error, with delays between retries.
Resolution
For asynchronous invocations
Review your Lambda function's Amazon CloudWatch Logs to verify the following:
- If the duplicate invocations have the same request ID or not
- If the duplicate invocations returned errors or timed out
Then, do one of the following based on your use case:
For duplicate invocations that returned errors or timed out and that have the same request ID
Note: Duplicate invocations that return errors or timeout and that have the same request ID indicate that the Lambda service retried the function.
Configure error handling for asynchronous invocations to reduce the number of times that your Lambda function retries failed asynchronous invocation requests.
For more information, see Error handling and automatic retries in AWS Lambda.
For duplicate invocations that didn't return errors or timeout
Note: Duplicate invocations that don't return errors or timeout indicate client-side retries.
- Make sure that your Lambda function's code is idempotent and capable of handling messages multiple times.
- Make sure that your Lambda function has its concurrency limit set high enough to handle the number of invocation requests it receives.
- Identify and resolve any errors that your Lambda function returns.
Note: To troubleshoot function invocation failures, see How do I troubleshoot Lambda function failures?
For synchronous invocations
Note: Synchronous invocation retry behavior varies between AWS services, based on each service's event source mapping. For more information, see Event-driven invocation.
- Make sure that your Lambda function's code is idempotent and capable of handling messages multiple times.
- Identify and resolve any errors that your Lambda function returns.
Note: To troubleshoot function invocation failures, see How do I troubleshoot Lambda function failures?
Related information
Did this article help?
Do you need billing or technical support?