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.

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.