Ravindra BagaleCourses & study guides मराठी Track your progress

Ravi Sir's Cards › AWS › Lambda triggers

AWS Cloud

AWS Lambda triggers: S3, EventBridge, SQS, SNS, cold starts and retries

This page keeps the next Lambda cards on one topic page, after the “what is Lambda” and first-function page. It has the ten cards from “AWS Lambda triggers: S3, EventBridge, SQS and SNS explained”. Later packs (API Gateway, DynamoDB, and the project) can be their own topic pages later.

Each card still has its image and its original text. Under each group you will also find a short Why, What, How example, and an exam tip, in easy English. The names, bucket prefixes and schedule times in the stories are made up for learning.

S3, EventBridge, SQS and SNS triggers

Why this matters

Manual thumbnail jobs miss uploads, and a cron job on one EC2 dies with the instance. Events do not sleep, and a cloud schedule stays up.

What it is

A trigger is what starts the function. S3 can invoke Lambda on ObjectCreated for a prefix or suffix, such as images/ and .jpg. EventBridge Scheduler (or rules) can invoke Lambda on a cron or rate, for example a nightly job at 21:00 in Asia/Calcutta. SQS queues work so bursty producers can buffer; Lambda uses an event source mapping. SNS topics fan out one message to many subscribers, including Lambda. A cold start is the first invoke on a fresh environment, when the runtime and package load; later warm invokes reuse the environment. Layers can share libraries (these cards say a maximum of five layers). Async invokes retry on failure, so handlers must be idempotent.

How it works — a real example

Suppose an upload of hero.jpg under images/ starts a function that writes thumbs/hero.jpg — not back into the same images/ prefix. A stop-dev function runs at 9 PM India time on an EventBridge schedule. An order service publishes to SNS, and both an email Lambda and an analytics Lambda run. If an S3 trigger fails twice, the event can go to a DLQ you configure. The names are made up for learning.

Common mistake / exam tip

Do not write back to the same S3 prefix you listen on — that can recurse, and the bill and throttling explode until you stop the trigger. Keep packages small. Use provisioned concurrency only when a latency SLA needs it.

S3 ObjectCreated trigger

Revision card: S3 ObjectCreated trigger. Manual thumbnail jobs miss uploads. Events never sleep. S3 can invoke Lambda on ObjectCreated for a prefix or suffix. Add trigger → S3 → bucket → event type → prefix images/ suffix .jpg. Upload hero.jpg → Lambda writes thumbs/hero.jpg.
Card 1 of 10: S3 ObjectCreated trigger · Download PNG
Read card text

What this card says

Why do we need it?

Manual thumbnail jobs miss uploads. Events never sleep.

What is it?

S3 can invoke Lambda on ObjectCreated for a prefix or suffix.

How to do it

Add trigger → S3 → bucket → event type → prefix images/ suffix .jpg. s3:ObjectCreated:*

Example

Upload hero.jpg → Lambda writes thumbs/hero.jpg.

EventBridge schedules

Revision card: EventBridge schedules. Cron on one EC2 dies with the instance. Cloud schedules stay. EventBridge Scheduler (or rules) invokes Lambda on a cron or rate. Create schedule → cron 0 21 * * ? * Asia/Calcutta → target Lambda. Nightly stop-dev Lambda runs at 9 PM India time.
Card 2 of 10: EventBridge schedules · Download PNG
Read card text

What this card says

Why do we need it?

Cron on one EC2 dies with the instance. Cloud schedules stay.

What is it?

EventBridge Scheduler (or rules) invokes Lambda on a cron or rate.

How to do it

Create schedule → cron 0 21 * * ? * Asia/Calcutta → target Lambda. cron(0 21 * * ? *)

Example

Nightly stop-dev Lambda runs at 9 PM India time.

SQS and SNS with Lambda

Revision card: SQS and SNS with Lambda. Bursty producers need a buffer. Many listeners need fan-out. SQS queues work; SNS topics notify many subscribers including Lambda. Event source mapping for SQS. SNS subscription protocol Lambda. Order service publishes to SNS → Lambda email + Lambda analytics both run.
Card 3 of 10: SQS and SNS with Lambda · Download PNG
Read card text

What this card says

Why do we need it?

Bursty producers need a buffer. Many listeners need fan-out.

What is it?

SQS queues work; SNS topics notify many subscribers including Lambda.

How to do it

Event source mapping for SQS. SNS subscription protocol Lambda.

Example

Order service publishes to SNS → Lambda email + Lambda analytics both run.

Cold starts, layers, retries

Revision card: Cold starts, layers, retries. First invoke after idle feels slow. Shared libs bloat every zip. Cold start = new environment. Layers share libraries. Async invokes retry on failure. Keep packages small; put heavy deps in a layer; design handlers idempotent. S3 trigger fails twice then can go to a DLQ you configure.
Card 4 of 10: Cold starts, layers, retries · Download PNG
Read card text

What this card says

Why do we need it?

First invoke after idle feels slow. Shared libs bloat every zip.

What is it?

Cold start = new environment. Layers share libraries. Async invokes retry on failure.

How to do it

Keep packages small; put heavy deps in a layer; design handlers idempotent. max 5 layers

Example

S3 trigger fails twice then can go to a DLQ you configure.

Sync vs async, SQS vs SNS, and exam points

Why this matters

Teams mix up who waits for the result, and they pick the wrong bus: a queue when they needed fan-out, or a topic when they needed a backlog.

What it is

A synchronous invoke means the caller waits for the response (API Gateway to Lambda is the usual example, with an HTTP 200 and a body). An asynchronous invoke queues the event and Lambda runs later (S3, SNS, and EventBridge commonly do this). SQS is a queue: competing consumers pull, and work can sit as a backlog. SNS is a topic: one message is pushed to many subscribers (email, Lambda, SQS, and so on). Async retries can deliver the same event more than once, so the handler must be safe to run again — for example, key writes by event id and skip if already processed.

How it works — a real example

Suppose checkout jobs go to SQS and a worker Lambda drains the backlog. When an order is placed, SNS notifies an email Lambda and a stock Lambda at the same time. A user-facing API stays synchronous so the browser can show the result. The names are made up for learning.

Common mistake / exam tip

Use SQS when work must be processed with a backlog and retries per consumer. Use SNS when one event must notify many. If the invoke is async, design for at-least-once delivery.

Comparison: Who waits for the result?

Comparison: Synchronous invoke vs Asynchronous invoke. Synchronous invoke: Caller waits for the response. Asynchronous invoke: Event is queued; Lambda runs later.
Card 5 of 10: Comparison: Who waits for the result? · Download PNG
Read card text

What this card says

Synchronous invoke

Caller waits for the response.

Asynchronous invoke

Event is queued; Lambda runs later.

Key points

API Gateway → Lambda. S3, SNS, EventBridge → Lambda.

Example

HTTP 200 with body.

Use when

User-facing APIs. Background processing.

Comparison: Pattern

Comparison: Amazon SQS vs Amazon SNS. Amazon SQS: Queue: buffer work for consumers. Amazon SNS: Topic: fan-out one message to many.
Card 6 of 10: Comparison: Pattern · Download PNG
Read card text

What this card says

Amazon SQS

Queue: buffer work for consumers.

Amazon SNS

Topic: fan-out one message to many.

Key points

Competing consumers pull. Push to email, Lambda, SQS…

Example

Checkout jobs backlog.

Use when

Smooth bursts. Broadcast events.

Interview: Why avoid writing back to the same S3 prefix you listen on?

Interview card: Why avoid writing back to the same S3 prefix you listen on?. Your write can create another ObjectCreated event and recurse. Bills and throttling explode until you stop the trigger. Read images/; write thumbs/ or another bucket.
Card 7 of 10: Interview: Why avoid writing back to the same S3 prefix you listen on? · Download PNG
Read card text

What this card says

What it is

Your write can create another ObjectCreated event and recurse.

Why it matters

Bills and throttling explode until you stop the trigger.

How / example

Read images/; write thumbs/ or another bucket.

Interview: What is a cold start?

Interview card: What is a cold start?. First invoke on a fresh environment loads runtime and your package. Later warm invokes reuse the environment and are faster. Shrink deps; provisioned concurrency only when latency SLAs need it.
Card 8 of 10: Interview: What is a cold start? · Download PNG
Read card text

What this card says

What it is

First invoke on a fresh environment loads runtime and your package.

Why it matters

Later warm invokes reuse the environment and are faster.

How / example

Shrink deps; provisioned concurrency only when latency SLAs need it.

Interview: SQS vs SNS for Lambda — when each?

Interview card: SQS vs SNS for Lambda — when each?. SQS buffers and retries per consumer. SNS fans out one message to many. Use SQS when work must be processed with backlog. Use SNS for notify-many. Checkout → SQS → worker Lambda. Order placed → SNS → email + stock Lambdas.
Card 9 of 10: Interview: SQS vs SNS for Lambda — when each? · Download PNG
Read card text

What this card says

What it is

SQS buffers and retries per consumer. SNS fans out one message to many.

Why it matters

Use SQS when work must be processed with backlog. Use SNS for notify-many.

How / example

Checkout → SQS → worker Lambda. Order placed → SNS → email + stock Lambdas.

Interview: Why must async handlers be idempotent?

Interview card: Why must async handlers be idempotent?. Retries can deliver the same event more than once. Re-applying the same work must be safe. Key writes by event id; skip if already processed.
Card 10 of 10: Interview: Why must async handlers be idempotent? · Download PNG
Read card text

What this card says

What it is

Retries can deliver the same event more than once.

Why it matters

Re-applying the same work must be safe.

How / example

Key writes by event id; skip if already processed.

FAQ

How do I run Lambda when a file lands in S3?

Add an S3 ObjectCreated trigger, optionally limited to a prefix and suffix. The example on these cards is images/ and .jpg.

Why should the function not write back to the same S3 prefix?

That write can create another ObjectCreated event and recurse. Read from one prefix or bucket, and write to another, such as thumbs/.

How do I run Lambda on a schedule?

Use EventBridge Scheduler or rules with a cron or rate. The lab example is cron 0 21 * * ? * in Asia/Calcutta, which is 9 PM India time.

When do I use SQS vs SNS with Lambda?

SQS buffers work for consumers and handles backlog. SNS fans out one message to many subscribers. You can also subscribe an SQS queue to an SNS topic.

What is the difference between a synchronous and an asynchronous invoke?

Synchronous: the caller waits for the result (typical for API Gateway). Asynchronous: the event is queued and Lambda runs later (typical for S3, SNS, EventBridge).

What is a cold start?

The first invoke on a fresh environment loads the runtime and your package, so it can feel slower. Later warm invokes reuse the environment. Shrink dependencies; use provisioned concurrency only when you have a latency SLA.

Why must async handlers be idempotent?

Retries can deliver the same event more than once. Re-applying the same work must be safe, for example by keying writes on an event id.

What do these cards say about Lambda layers?

Layers can share libraries so every zip is not bloated. These cards say a maximum of five layers. Keep packages small.

These chapter pages are already on the site (checked live, HTTP 200, on 19 Nov 2026):

See all AWS revision cards