Notifying and Buffering Pipeline Work with Amazon SNS and Amazon SQS
This lesson explains how Amazon SNS delivers notifications and fans out messages, and how Amazon SQS buffers work durably between producers and consumers, so pipelines report failures and pass work reliably.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish the roles of SNS and SQS.
- Fan out messages to independent consumers.
- Configure queues with visibility timeouts and dead-letter queues.
- Combine CloudWatch alarms and event rules to monitor pipelines.
The two services
Amazon SNS and Amazon SQS are both messaging services but play different roles. SNS is publish and subscribe: a message published to a topic is pushed immediately to every subscriber, such as email, SMS, HTTP endpoints, Lambda functions, SQS queues or chat channels through Amazon Q Developer in chat applications. It keeps no messages, so in pipelines it sends alerts and fans one event out to several consumers.
SQS is a queue: messages wait, for up to 14 days, until a consumer polls and processes them, and each message is handled by one consumer. That makes it a durable buffer that absorbs bursts, lets consumers work at their own pace and retries failed messages. Combining them, an SNS topic delivering to several SQS queues, gives each consumer its own buffered copy. The following table summarises the differences.
SNS or SQS?
Fan-out
Publishing to an SNS topic subscribed by several SQS queues gives each consumer its own copy of every message and its own buffer and retries. Subscription filter policies deliver only matching messages to each queue, for example only events for one region.
Reliable queues
SQS queues must be configured so that failures are handled safely. The visibility timeout, the time a received message stays hidden from other consumers, must be longer than the time needed to process a message; otherwise the message reappears while it is still being processed and is processed twice.
A dead-letter queue with a maximum receive count sets aside messages that fail repeatedly, often called poison messages, so they do not block the queue or retry forever. Where the order of messages matters, or each message must be processed exactly once within a group, FIFO queues provide ordering and deduplication within each message group.
The following diagram shows what happens when processing outlasts the visibility timeout.

Queue problems
A monitoring pattern
Pipelines should be monitored so that failures are detected promptly, and a typical pattern combines two mechanisms. CloudWatch alarms watch pipeline metrics, such as job duration, the number of failed records, Kinesis iterator age and Redshift queue time, and publish to an SNS topic when a service level agreement is at risk of being breached.
Amazon EventBridge rules catch job failures the moment they happen, from services such as Glue, EMR and Step Functions, and publish them to SNS as well. Subscribers to the topic, such as an email list, a chat channel or an incident management tool, then receive both kinds of alert in one place.
The following diagram shows the topic, the three queues and their consumers.

One event, three consumers
When a curated dataset is published, three systems must react: a data quality job, a search indexer and a partner export. Each must retry independently if it fails. The design publishes one message to an SNS topic subscribed by three SQS queues, configured as follows.
| Queue | Consumer | Configuration |
|---|---|---|
| dq-queue | Lambda that starts a Glue Data Quality run | Visibility timeout 5 minutes; DLQ after 3 receives |
| index-queue | Lambda that updates OpenSearch | Filter policy: only datasets tagged searchable |
| export-queue | Partner export job | Maximum concurrency 2 to respect the partner's limits |
If the search indexer fails, its messages wait in its own queue and then its dead-letter queue, while the other two consumers are unaffected. A CloudWatch alarm on each DLQ's depth notifies the team.
How is a team alerted when a Glue job fails?
Show answer
An EventBridge rule on Glue job state changes routes FAILED events to an SNS topic.
Exam Tips
Remember for the exam
- To alert when a Glue job fails, route an EventBridge rule on Glue job state to SNS.
- For durable buffering between steps with retries, use SQS with a dead-letter queue.
- To send one message to several queues, use SNS fan-out.
- To raise an alarm when a pipeline runs too long, send a CloudWatch alarm to SNS.
- Set the SQS visibility timeout longer than the processing time.