SkillSprout
Chapter 9 · Lesson 4
Intermediate
7 min read

Event-Driven Automation: SNS, SQS, SES, Step Functions, Lambda and S3 Events

Overview

Event-driven automation reacts to things that happen instead of polling for them: an object lands in S3, an alarm fires, a message arrives. A SysOps administrator wires these pieces together so common operational tasks run by themselves. The SOA-C03 guide lists SNS, SQS, SES, Step Functions, Lambda, EventBridge, Data Firehose and Athena among in-scope services, and skill 3.2.2 is "implement event-driven automation by using AWS services".

Picture a post office. SNS is the loudspeaker that announces news to everyone subscribed; SQS is the mailbox where messages wait until a worker is ready; SES sends the email; Step Functions is the supervisor following a flowchart with retries and approvals; Lambda is the clerk doing each small task; EventBridge is the sorting room that routes events to the right place.

You do not need to design systems, but you must know which service to use for fan-out, buffering, notifications, orchestration and log analytics, and how to diagnose them when they fail.

Key Concepts

  • SNS is pub/sub (topics with email, SMS, HTTP, SQS, Lambda, Firehose subscribers). Standard topics are at-least-once with best-effort ordering; FIFO topics give ordering and deduplication to SQS FIFO queues. Message filtering policies route subsets.
  • SQS decouples producers and consumers. Visibility timeout (default 30 s) hides a message while processing; DLQ with maxReceiveCount captures poison messages; long polling reduces empty receives; FIFO gives ordering at lower throughput.
  • Fan-out: SNS topic -> multiple SQS queues. SQS scales consumers: ASG on ApproximateNumberOfMessagesVisible per instance.
  • Amazon SES sends transactional and bulk email; needs verified identities (domain or address), DKIM/SPF/DMARC, and starts in the sandbox (limited recipients) until production access is granted; monitor bounce and complaint rates.
  • Step Functions orchestrates workflows (Standard up to 1 year, Express for high-volume short runs) with Retry/Catch, parallel states, wait states and optimized integrations with 200+ services.
  • Lambda triggers: S3, SNS, SQS (event source mapping), DynamoDB Streams, EventBridge, API Gateway; async retries twice and supports destinations/DLQs.
  • S3 Event Notifications deliver to SNS, SQS, Lambda or EventBridge (richer filtering, more targets); events can lag seconds and require a resource policy permitting S3 to publish.
  • Amazon Data Firehose loads streaming data into S3, Redshift, OpenSearch or HTTP endpoints with optional Lambda transform; Athena queries data in S3 with SQL (for example CloudTrail, VPC Flow Logs, ALB logs).

Detailed Notes

Choosing the integration service

NeedService
Notify many subscribers at once (email, SMS, queues, Lambda)SNS
Buffer work so consumers process at their own paceSQS
Route AWS and SaaS events by pattern, schedule jobsEventBridge
Multi-step workflow with retries, branching, human approvalStep Functions
Send application or marketing email at scaleSES
Stream logs/records into S3 with batchingData Firehose
Ad hoc SQL over log files in S3Athena

SNS and SQS fan-out

bash
aws sns create-topic --name ops-alerts
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:111122223333:ops-alerts --protocol email --notification-endpoint oncall@example.com
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:111122223333:ops-alerts --protocol sqs \
  --notification-endpoint arn:aws:sqs:us-east-1:111122223333:ticketing \
  --attributes '{"FilterPolicy":"{\"severity\":[\"critical\"]}","RawMessageDelivery":"true"}'

The SQS queue policy must allow sns.amazonaws.com to sqs:SendMessage with aws:SourceArn of the topic. If using SSE-KMS on the topic or queue, the key policy must allow the publishing service, otherwise messages silently fail (a frequent exam trap). Services such as CloudWatch alarms, S3 and AMP publish to topics, so the topic access policy must trust them.

SQS operations

SymptomCauseFix
Messages processed twiceVisibility timeout shorter than processing timeRaise visibility timeout (at least 6x Lambda timeout for Lambda consumers)
Messages in DLQPoison message after maxReceiveCountInspect, fix consumer, redrive from DLQ
Empty receives and costShort pollingSet WaitTimeSeconds = 20 (long polling)
Backlog growingToo few consumersScale on backlog per instance; alarm on ApproximateAgeOfOldestMessage
FIFO throughput limitedSingle message groupUse more MessageGroupIds, high-throughput mode
bash
aws sqs create-queue --queue-name orders --attributes '{"VisibilityTimeout":"120","ReceiveMessageWaitTimeSeconds":"20","RedrivePolicy":"{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:111122223333:orders-dlq\",\"maxReceiveCount\":\"5\"}"}'
aws sqs start-message-move-task --source-arn arn:aws:sqs:us-east-1:111122223333:orders-dlq

Step Functions with retries

json
{ "StartAt": "Snapshot",
  "States": {
    "Snapshot": { "Type": "Task", "Resource": "arn:aws:states:::aws-sdk:ec2:createSnapshot",
      "Parameters": { "VolumeId.$": "$.volumeId" },
      "Retry": [ { "ErrorEquals": ["States.TaskFailed"], "IntervalSeconds": 5, "MaxAttempts": 3, "BackoffRate": 2 } ],
      "Catch": [ { "ErrorEquals": ["States.ALL"], "Next": "NotifyFailure" } ], "Next": "Done" },
    "NotifyFailure": { "Type": "Task", "Resource": "arn:aws:states:::sns:publish",
      "Parameters": { "TopicArn": "arn:aws:sns:us-east-1:111122223333:ops-alerts", "Message.$": "$.Cause" }, "End": true },
    "Done": { "Type": "Succeed" } } }

Standard workflows suit long-running operational runbooks with an audit history; Express suits high-volume event processing. Troubleshoot using the execution history and CloudWatch Logs; typical failures are IAM permissions on the state machine role and timeouts.

S3 event notifications

bash
aws s3api put-bucket-notification-configuration --bucket uploads --notification-configuration '{
  "LambdaFunctionConfigurations": [ { "LambdaFunctionArn": "arn:aws:lambda:us-east-1:111122223333:function:scan",
    "Events": ["s3:ObjectCreated:*"], "Filter": { "Key": { "FilterRules": [ { "Name": "suffix", "Value": ".csv" } ] } } } ] }'

Do not trigger a function from the same prefix it writes to (recursion). If notifications never arrive, check the destination permission (Lambda resource policy, SQS/SNS policy), overlapping prefix filters and the bucket Region. Use EventBridge for archives, replay and multiple targets.

SES essentials

TaskDetail
Verify identityDomain (DKIM CNAMEs) or email address
Leave sandboxRequest production access; sandbox only sends to verified addresses and limits volume
DeliverabilityPublish SPF, DKIM, DMARC; keep bounce < 5% and complaint < 0.1%
MonitorConfiguration set publishes events to CloudWatch, SNS or Firehose; account-level suppression list

Log analytics with Firehose and Athena

sql
SELECT eventname, useridentity.arn, COUNT(*) AS calls
FROM cloudtrail_logs
WHERE eventtime > '2025-01-01' AND errorcode = 'AccessDenied'
GROUP BY eventname, useridentity.arn ORDER BY calls DESC LIMIT 20;

Partition tables (by date/Region) and store logs in Parquet to cut Athena scanned bytes and cost; Firehose can convert and compress while delivering CloudWatch Logs subscription data to S3.

Real World Example

Scenario – automated upload processing. Partners upload CSV files to S3. An S3 event notification sends ObjectCreated events to an SQS queue; a Lambda function with an event source mapping validates each file. Failures after five attempts land in a DLQ and raise a CloudWatch alarm on ApproximateNumberOfMessagesVisible.

Valid files start a Step Functions workflow (transform, load, notify) with retries. Completion and failure messages go to an SNS topic that emails the partner through SES-backed templates and posts to the on-call chat. Weekly, the team uses Athena over CloudTrail and ALB logs in S3 to audit access patterns.

Architecture Diagram

Event-driven file processing
Architecture
Event pipeline
S3 uploads
SQS+ DLQ
Lambda
Step Functions
SNSemail / SES
  1. 1A file lands in S3 and generates an ObjectCreated event.
  2. 2The event is queued in SQS so spikes are buffered.
  3. 3Lambda processes messages; repeated failures go to the DLQ.
  4. 4Step Functions orchestrates multi-step processing with retries and catches.
  5. 5SNS notifies people and systems; Athena analyses the resulting logs.

Best Practices

  • ✓Put SQS between event sources and consumers with a DLQ, long polling and a visibility timeout longer than processing time.
  • ✓Use SNS message filtering and fan-out to SQS instead of custom routing code.
  • ✓Check resource policies and KMS key policies whenever a service-to-service notification does not arrive.
  • ✓Use Step Functions for multi-step runbooks needing retries, branching or approvals.
  • ✓Move SES out of the sandbox early, authenticate with DKIM/SPF/DMARC and alarm on bounce and complaint rates.

Common Interview Questions

Exam Tips

SOA-C03 focus

  • Decouple and buffer -> SQS; notify many -> SNS; orchestrate steps with retries -> Step Functions.
  • Poison messages -> DLQ with maxReceiveCount; duplicate processing -> visibility timeout too low.
  • SES in the sandbox can only send to verified addresses; production access removes the limit.
  • Query logs in S3 with SQL cheaply -> Athena with partitioning/Parquet; load streaming data to S3 -> Data Firehose.

Chapter quiz

Infrastructure as Code, Resource Sharing and Event-Driven Automation · 10 questions

  1. 1.A team writes infrastructure in TypeScript with the AWS CDK. The first cdk deploy in a new account fails with a message that the toolkit stack must be deployed. What should the operator do?

  2. 2.Multiple engineers run terraform apply against the same environment and occasionally corrupt state. Which change BEST addresses this on AWS?

  3. 3.A company must deploy a baseline Config recorder role to all current and future accounts in three Regions with minimal manual work. Which solution fits?

  4. 4.Several accounts must use the same Transit Gateway owned by a networking account, without duplicating it. Which service enables this?

  5. 5.Two teams unknowingly created VPCs with the same 10.0.0.0/16 range, and peering fails. Which service would have prevented this?

  6. 6.A production release must expose only 10% of users to the new version initially, roll back automatically if error alarms fire, and keep the old version available. Which strategy is BEST?

  7. 7.An ECS service using awsvpc networking fails new tasks with a network interface error, and the private subnets show zero available IP addresses. What is the BEST long-term fix?

  8. 8.A CloudFormation stack update fails and then shows UPDATE_ROLLBACK_FAILED because a resource was deleted manually. What should the operator do?

  9. 9.Messages in an SQS queue are being processed repeatedly by a consumer that takes about 90 seconds per message. The queue uses default settings. What is the MOST likely cause?

  10. 10.A SaaS application must send transactional email to customers through Amazon SES but only a few verified test addresses receive mail. What should the operator do?

0 of 10 answered

Finished this lesson?

0 of 46 lessons done · 0% of the course