Skip to content

How do I prevent duplicate Lambda function invocations?

2 minute read
0

My AWS Lambda function received more than one invocation request for a single event.

Short description

For synchronous invocations, the clients and AWS services that invoke a Lambda function retries the operation. For asynchronous invocations, Lambda automatically retries function errors twice.

Resolution

To prevent duplicate Lambda function invocations, take the following actions based on the invocation method that you use.

Note: To troubleshoot function invocation failures, see How do I troubleshoot Lambda function failures?

Asynchronous invocations

Review your Lambda function's Amazon CloudWatch Logs. Verify if the duplicate invocations have the same request ID, and 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 duplicate invocations that didn't return errors or timeout

Note: Duplicate invocations that don't return errors or timeout indicate client-side retries.

Complete the following actions:

Note: To troubleshoot function invocation failures, see How do I troubleshoot Lambda function failures?

Synchronous invocations

Note: Synchronous invocation retry behavior varies between AWS services, based on each service's event source mapping. For more information, see Invoking Lambda with events from other AWS services.

Make sure that your Lambda function's code is idempotent and capable of handling messages multiple times. Then, identify and resolve any errors that your Lambda function returns.

Related information

Working with CloudTrail event history

Best practices for working with AWS Lambda functions

AWS OFFICIALUpdated 4 months ago