AWS Lambda

Understanding Lambda

Event Sources

AWS Lambda functions execute in response to events generated by other AWS services, streams, or queues. Understanding these event sources—and their invocation models—is essential for building reliable, scalable serverless applications.

The image illustrates event sources for AWS Lambda, showing a push model with icons for a camera, mobile device, S3 bucket, and API Gateway, and a pull model with an icon for a stream service.

Invocation Models

AWS Lambda supports two primary invocation models:

  • Push model: An AWS service invokes your function directly when an event occurs.
  • Pull model: Lambda polls streams or queues and triggers your function when new records or messages arrive.

Push Model

In the push model, event sources call Lambda directly. Push invocations are categorized as synchronous or asynchronous:

Synchronous Invocations

  • The caller waits for Lambda to finish and returns the function’s response.
  • Typical sources: API Gateway, Amazon CloudFront, Amazon Cognito.
  • Failures are returned immediately; no automatic retries.

The image illustrates a synchronous push model source type, showing an API Gateway and a Lambda function with a note indicating no retries.

Asynchronous Invocations

  • The service acknowledges receipt immediately, while Lambda processes the event in the background.
  • Automatic retry policy:
    1. First retry after 1 minute
    2. Second retry after 2 minutes
  • Failed events can be routed to a dead-letter queue (DLQ) or destinations (e.g., EventBridge for failures, SNS for successes).

The image illustrates an asynchronous push model source type, showing a sequence of three attempts with increasing time intervals (1 minute, 2 minutes) and an icon representing AWS Lambda.

Note

Configure a dead-letter queue or destinations to capture events after retry attempts are exhausted.

The image illustrates an asynchronous push model source type, showing a source connected to AWS Lambda, which then connects to destinations like EventBridge and Simple Notification Service.

Push Model Sources Overview

Invocation TypeEvent SourcesRetry Behavior
SynchronousAPI Gateway, CloudFront, CognitoNo retries
AsynchronousS3, CloudWatch Events, SNS, EventBridge, IoT2 retries (1m, 2m)

The image is a diagram showing "Push Model Source Types" divided into "Synchronous" and "Asynchronous" categories, with icons for services like CloudFormation, CloudFront, API Gateway, Cognito, CloudWatch, and others.


Pull Model

Lambda polls data sources for new records or messages, then invokes your function:

  • Streams (e.g., Amazon Kinesis Data Streams, DynamoDB Streams)
  • Queues (e.g., Amazon SQS)

The image shows a diagram titled "Pull Model Source Types" with two categories: "Streams" featuring two icons, and "Queues" with one icon.

Streams

  • Ideal for continuous data flows: application logs, metrics, real-time analytics.
  • Lambda polls each shard in sequence and sends batches of records.
  • On a processing failure, polling for that shard halts until the issue is resolved.

Queues

  • Used for discrete messages that are processed individually or in batches.
  • Lambda polls the queue at regular intervals and invokes your function with messages.

The image shows icons representing Amazon Simple Queueing Service and AWS Lambda, labeled under "Pull Model Source Types: Queues."

Pull Model TypeAWS ServiceRetry & DLQ Support
StreamsKinesis Data Streams, DynamoDBStops on failure per shard
QueuesAmazon SQSRetries until TTL; DLQ

Warning

Ensure your function’s IAM role has permission to poll streams or read from queues and to write to DLQs if configured.


This covers how AWS Lambda handles events via push and pull models. Next, we’ll explore the IAM permissions and security best practices for Lambda event sources.


Watch Video

Watch video content

Previous
Lambda Service Basics