Skip to Content

Event processing

Event-driven patterns on AWS - Lambda with SQS, SQS FIFO and SNS and their dead-letter queues, the SNS fan-out, S3 event notifications and EventBridge, intercepting API calls with CloudTrail, and API Gateway writing straight to Kinesis.

Lambda with SQS, SQS FIFO and SNS

Lambda with queues and topics: Lambda polls an SQS queue, and failed messages return to the queue and are retried until they move to the queue's dead-letter queue; with SQS FIFO, messages are processed in order and a failing message blocks its message group until it succeeds or moves to the DLQ; SNS invokes Lambda asynchronously, Lambda retries, then sends the event to an SQS dead-letter queue Lambda with queues and topics: Lambda polls an SQS queue, and failed messages return to the queue and are retried until they move to the queue's dead-letter queue; with SQS FIFO, messages are processed in order and a failing message blocks its message group until it succeeds or moves to the DLQ; SNS invokes Lambda asynchronously, Lambda retries, then sends the event to an SQS dead-letter queue

Where the retries happen, and where failures end up.
  • SQS + Lambda: Lambda polls the queue. A message that fails becomes visible again after the visibility timeout and is retried; after maxReceiveCount attempts, the queue moves it to its dead-letter queue (set on the SQS queue).
  • SQS FIFO + Lambda: messages are processed in order within each message group. A failing message is retried and blocks its group until it succeeds or moves to the DLQ.
  • SNS + Lambda: SNS invokes Lambda asynchronously. Lambda retries (twice by default), then sends the event to a DLQ (an SQS queue or SNS topic) or an on-failure destination, set on the Lambda side.

Fan-out: one message, many queues

  • Option 1: the application puts the message into each SQS queue itself. If it crashes between two puts, the queues disagree, and every new queue means a code change.
  • Option 2, fan-out: the application publishes once to an SNS topic, and every subscribed queue gets a copy. Add a consumer by adding a subscription. See SNS + SQS fan-out.

S3 event notifications

  • Events such as s3:ObjectCreated, s3:ObjectRemoved, s3:ObjectRestore, s3:Replication…
  • Filter on the object name (prefix and suffix, for example *.jpg).
  • Use case: generate thumbnails of images uploaded to S3.
  • A bucket can have as many S3 events as needed.
  • Targets: SNS, SQS (standard queues), Lambda.
  • Events are usually delivered in seconds, but sometimes take a minute or longer.

S3 events with Amazon EventBridge

Send all the bucket's events to EventBridge, then use rules:

  • advanced filtering with JSON rules (metadata, object size, name…);
  • many destinations: Step Functions, Kinesis Data Streams and Firehose, SQS FIFO, and many more AWS services;
  • EventBridge features: archive and replay events, reliable delivery.

See S3 events with Amazon EventBridge.

EventBridge: intercepting API calls

Intercepting API calls: a user calls DeleteTable on DynamoDB; CloudTrail logs the API call and sends it as an event to EventBridge, where a rule matches it and alerts the team through Amazon SNS Intercepting API calls: a user calls DeleteTable on DynamoDB; CloudTrail logs the API call and sends it as an event to EventBridge, where a rule matches it and alerts the team through Amazon SNS

React to any API call in the account.

CloudTrail records every API call in the account and delivers it to EventBridge as an event. A rule can match one call (here DeleteTable on DynamoDB) and alert through SNS, or start a Lambda function to fix things.

API Gateway: AWS service integration

API Gateway service integration: clients send requests to API Gateway, which writes them straight to Kinesis Data Streams without a Lambda function; Data Firehose reads the records, batches them and delivers JSON files to Amazon S3 API Gateway service integration: clients send requests to API Gateway, which writes them straight to Kinesis Data Streams without a Lambda function; Data Firehose reads the records, batches them and delivers JSON files to Amazon S3

An HTTPS front door for a stream, no code.

API Gateway can call AWS services directly (here Kinesis PutRecord), with no Lambda in between. API Gateway's features (authentication, throttling, API keys, usage plans) in front of the service without exposing AWS credentials to clients.

Real-world examples

  • An order system publishes OrderPlaced to one SNS topic; the shipping, invoicing and analytics queues each get a copy, and a fourth team subscribes later without touching the order code.
  • A security team alerts on DeleteBucket, StopLogging and DeleteTable calls with EventBridge rules on CloudTrail events.

Exam tips

  • "Send the same message to several services reliably" → SNS topic with SQS subscriptions (fan-out).
  • "Order matters and messages must not be lost when Lambda fails" → SQS FIFO + Lambda, with a DLQ.
  • "React to object uploads" → S3 event notifications; "advanced filtering, many targets, replay" → S3 → EventBridge.
  • "Alert when someone calls a specific API" → CloudTrail → EventBridge rule → SNS.
  • "Expose Kinesis (or SQS, DynamoDB) to clients over HTTPS without Lambda" → API Gateway AWS service integration.

Common traps

  • "Set the DLQ on Lambda for an SQS trigger." For SQS sources, the DLQ belongs to the queue (redrive policy). Lambda's own DLQ or destinations apply to asynchronous invocations, such as from SNS or S3.
  • "S3 notifications go to SQS FIFO." Not directly; use EventBridge.
  • "S3 events are instant." Usually seconds, sometimes a minute or more.

Check yourself

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt