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
- SQS + Lambda: Lambda polls the queue. A message that fails becomes visible again after the visibility timeout and is retried; after
maxReceiveCountattempts, 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
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 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
OrderPlacedto 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,StopLoggingandDeleteTablecalls 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
Publish once to an SNS topic and subscribe the three SQS queues (fan-out), or send the S3 upload event to the SNS topic. Each queue gets every message, and adding a fourth service needs no code change.
Make sure CloudTrail is on, then create an EventBridge rule matching CloudTrail events with source aws.dynamodb and event name DeleteTable, targeting an SNS topic the team subscribes to.
AWS documentation
Microservices and offloading downloads
A microservice architecture where each service is built its own way, synchronous and asynchronous patterns between services, their challenges, and how adding CloudFront offloads software update downloads from EC2.
Caching strategies
The places to cache along a request on AWS - CloudFront, API Gateway, ElastiCache and DAX - and how TTL, network, computation, cost and latency change as the cache moves closer to the user.