How do I prevent duplicate Lambda function invocations?
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?
"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 descriptionTo 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.ResolutionFor asynchronous invocationsReview your Lambda function's Amazon CloudWatch Logs to verify the following:If the duplicate invocations have the same request ID or notIf the duplicate invocations returned errors or timed outThen, 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 IDNote: 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 timeoutNote: 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 invocationsNote: 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 informationViewing events with CloudTrail Event historyBest practices for working with AWS Lambda functionsLambda function scalingWhy is my Lambda function retrying valid Amazon SQS messages and placing them in my dead-letter queue?Follow"