Lab 6 · SQS, SNS & EventBridge¶
Resilient · Est. time: 25–30 min · Cost: ✅ effectively Free — SQS, SNS, and EventBridge all have generous free tiers; this lab's handful of messages costs nothing. Clean up anyway.
Goal. Build the SNS → SQS fan-out pattern and see a message delivered to multiple durable queues, then create an EventBridge rule — the decoupling core of Topic 6.
Step 1 — Create two SQS queues¶
SQS → Create queue (Standard). Make orders-email and orders-analytics. Leave
defaults (visibility timeout 30s, retention 4 days).
Step 2 — Create an SNS topic and subscribe both queues (fan-out)¶
- SNS → Topics → Create topic (Standard), name
orders. - Create subscription on
orders: protocol Amazon SQS, endpoint =orders-emailARN. Repeat fororders-analytics. - When prompted, allow SNS to send to the queues (it adds the necessary queue access policy).
TOPIC=$(aws sns create-topic --name orders --query TopicArn --output text)
Q1_ARN=$(aws sqs get-queue-attributes --queue-url $Q1 --attribute-names QueueArn --query Attributes.QueueArn --output text)
Q2_ARN=$(aws sqs get-queue-attributes --queue-url $Q2 --attribute-names QueueArn --query Attributes.QueueArn --output text)
aws sns subscribe --topic-arn $TOPIC --protocol sqs --notification-endpoint $Q1_ARN
aws sns subscribe --topic-arn $TOPIC --protocol sqs --notification-endpoint $Q2_ARN
# (also add a queue policy allowing SNS to SendMessage — the console does this for you)
Step 3 — Publish once, receive twice¶
- SNS →
orders→ Publish message. Body:{"orderId":123}. - SQS → open each queue → Send and receive messages → Poll. The same message appears in both queues. One publish, two independent consumers — fan-out.
Why SNS → SQS, not SNS alone
Each SQS queue durably buffers the message so a down consumer loses nothing. SNS alone pushes once with limited retry. This fan-out-to-queues pattern is a very common exam answer.
Step 4 — An EventBridge rule (bonus)¶
- EventBridge → Rules → Create rule on the default bus.
- Schedule → fixed rate 5 minutes (or an event pattern matching an AWS service event).
- Target: the
ordersSNS topic (or a Lambda). Create. - This shows EventBridge's role: rules route events (by schedule or content) to targets — richer filtering and more sources than SNS.
Teardown¶
✅ What you should understand now¶
- SQS = a durable queue; each message is processed by one consumer then deleted.
- SNS = pub/sub; one publish is pushed to all subscribers.
- SNS → multiple SQS queues = durable fan-out: one event, several independent consumers, nothing lost if one is down.
- EventBridge routes events by schedule or content-based rules from many AWS/SaaS sources — reach for it over SNS when routing depends on event content.
- Visibility timeout, DLQs, and retention (4 days default) are the SQS knobs the exam probes.
Related: Learn — Decoupling & DR