Comparing Lambda invocation modes - AWS Lambda

Comparing Lambda invocation modes

Lambda functions can be invoked either synchronously or asynchronously, depending upon the trigger. In synchronous invocations, the caller waits for the function to complete execution and the function can return a value. In asynchronous operation, the caller places the event on an internal queue, which is then processed by the Lambda function.

Synchronous invocation Asynchronous invocation Polling invocation

AWS CLI

Elastic Load Balancing (Application Load Balancer)

Amazon Cognito

Amazon Lex

Amazon Alexa

Amazon API Gateway

Amazon CloudFront via Lambda@Edge

Amazon Kinesis Data Firehose

Amazon S3 Batch

Amazon S3

Amazon SNS

Amazon Simple Email Service

AWS CloudFormation

Amazon CloudWatch Logs

Amazon CloudWatch Events

AWS CodeCommit

AWS Config

AWS IoT

AWS IoT Events

AWS CodePipeline

Amazon DynamoDB

Amazon Kinesis

Amazon Managed Streaming for Apache Kafka (Amazon MSK)

Amazon SQS

Synchronous invocations are well suited for short-lived Lambda functions. Although Lambda functions can run for up to 15 minutes, synchronous callers may have shorter timeouts. For example, API Gateway has a 29-second integration timeout, so a Lambda function running for more than 29 seconds will not return a value successfully. In synchronous invocations, if the Lambda function fails, retries are the responsibility of the trigger.

In asynchronous invocations, the caller continues with other work and cannot receive a return value from the Lambda function. The function can send the result to a destination, configurable based on success or failure. The internal queue between the caller and the function ensures that messages are stored durably. The Lambda service scales up the concurrency of the processing function as this internal queue grows. If an error occurs in the Lambda function, the retry behavior is determined by the Lambda service.

AWS service Invocation type Retry behavior

Amazon API Gateway

Synchronous

None – returns error to the client

Amazon S3

Asynchronous

Retries with exponential backoff

Amazon SNS

Asynchronous

Retries with exponential backoff

Amazon DynamoDB Streams

Synchronous from poller

Retries until data expiration (24 hours)

Amazon Kinesis

Synchronous from poller

Retries until data expiration (24 hours to 7 days)

AWS CLI

Synchronous/Asynchronous

Configured by CLI call

AWS SDK

Synchronous/Asynchronous

Application-specific

Amazon SQS

Synchronous from poller

Retries until Message Retention Period expires or is sent to a dead-letter queue

To learn more, read Invoking AWS Lambda functions and Introducing AWS Lambda Destinations.