Study guide
Technical reference and lesson notes
Purpose of This Lesson
Amazon Simple Notification Service (Amazon SNS) is a fully managed publish/subscribe messaging service for distributing notifications to multiple subscribers. The core exam concept is distinguishing SNS push-based delivery from Amazon SQS pull-based message consumption.
SNS is especially useful when one published message must be delivered to many independent consumers or endpoint types.
Key Concepts
SNS topics
A topic is the central distribution point for SNS messages:
- A publisher sends a message to an SNS topic.
- Subscribers register their endpoints with the topic.
- SNS forwards the message to the subscribed endpoints.
A single topic can deliver messages to multiple endpoint types, such as:
- Amazon SQS queues
- AWS Lambda functions
- HTTP or HTTPS webhooks
- Email recipients
- SMS destinations
- Mobile push endpoints
If many email recipients subscribe to the same topic, each recipient receives the published notification.
Push-based delivery
SNS uses a push-based model. When a message is published, SNS attempts to deliver it to each subscription rather than requiring each consumer to poll the service.
This makes SNS appropriate for broadcasting notifications and distributing events to many subscribers.
SNS compared with SQS
| Characteristic | Amazon SNS | Amazon SQS |
|---|---|---|
| Messaging model | Publish/subscribe | Queue-based messaging |
| Delivery behavior | Pushes messages to subscribers | Consumers pull or poll for messages |
| Primary pattern | One-to-many or many-to-many distribution | Decoupling and buffering between producers and consumers |
| Central resource | Topic | Queue |
| Typical use | Broadcast notifications or fan-out | Reliable asynchronous processing by workers |
SNS and SQS are often used together rather than as alternatives. SNS distributes a message, while SQS provides a queue for each independent processing path.
SNS-to-SQS fan-out
The SNS-to-SQS fan-out pattern uses one SNS topic with multiple subscribed SQS queues:
Publisher
|
v
SNS topic
/ \\
v v
SQS SQS
queue queue
When the publisher sends a message to the topic, SNS forwards it to every subscribed queue. Each queue can then be processed independently by its own consumers, workers, or application component.
This pattern is valuable when different systems need to react to the same event but require separate processing rates, retry behavior, or downstream workflows.
The subscription configuration and the permissions required for SNS to deliver to the queues must be correctly configured.
Transport protocols and endpoints
SNS supports several delivery destinations and protocols, including:
- HTTP and HTTPS endpoints
- SMS
- Lambda functions
- SQS queues
- Mobile push endpoints
The appropriate destination depends on whether the subscriber needs application processing, web integration, direct human notification, or durable queue-based consumption.
Exam-Relevant Takeaways
- Amazon SNS is a fully managed, highly available, durable, and secure publish/subscribe service.
- An SNS topic is the access point to which publishers send messages and subscribers connect.
- SNS is push-based: messages are forwarded to subscribers after publication.
- Amazon SQS is pull-based: consumers poll a queue and retrieve messages for processing.
- SNS supports fan-out to many subscribers, including multiple SQS queues.
- SNS can deliver a single publication to different endpoint types at the same time.
- SNS-to-SQS fan-out is a common decoupling pattern for distributing one event to several independent processing pipelines.
- When an SNS topic delivers to SQS queues, subscription and delivery permissions must be configured correctly.
Architecture Decision Guide
| Requirement | Prefer | Reason |
|---|---|---|
| Notify many subscribers when an event occurs | SNS topic | Push-based one-to-many distribution |
| Allow workers to retrieve messages independently | SQS queue | Consumers pull messages when ready |
| Send one event to multiple independent applications | SNS with multiple subscriptions | Fan-out to separate subscribers |
| Provide durable buffering for a processing component | SQS, optionally subscribed to SNS | The queue separates publication from consumption |
| Invoke a function when a notification is published | SNS subscription to Lambda | SNS pushes the message to the function endpoint |
| Send notifications to web integrations | SNS with HTTP/HTTPS subscription | Supports webhook-style delivery |
| Notify people directly | SNS email or SMS delivery | Human-facing notification endpoints |
Common Exam Traps
- Confusing push and pull: SNS pushes notifications to subscribers; SQS consumers poll queues.
- Using SNS when independent buffering is required: SNS distributes the message, but SQS is the queueing component for each processing path.
- Assuming SNS sends only to email or SMS: SNS also supports Lambda, SQS, HTTP/HTTPS, and mobile push endpoints.
- Missing the fan-out clue: If multiple applications must receive the same event independently, SNS with multiple subscriptions is usually the relevant pattern.
- Ignoring permissions: An SNS topic and an SQS queue must be configured so that delivery to the queue is authorized.
- Treating a topic as a queue: A topic is a publication and distribution point, not a worker-consumption queue.
Real-World Engineer Notes
Use SNS when the main requirement is distribution. Use SQS when the main requirement is controlled asynchronous processing by consumers.
Combining the services provides a useful separation of concerns:
- SNS handles event distribution and fan-out.
- Each SQS queue represents an independent consumer or processing workflow.
- Consumers of each queue can process messages at their own pace.
This design also prevents one consumer’s processing model from being tightly coupled to another consumer’s implementation. For example, an analytics workflow and an order-processing workflow can each subscribe through their own queue while receiving the same published event.
Quick Reference Summary
- SNS: Managed, push-based publish/subscribe messaging.
- Topic: SNS distribution point for publishers and subscribers.
- Subscriber: An endpoint receiving messages from a topic.
- SQS: Pull-based queue service used by consumers that poll for messages.
- Fan-out: One SNS message delivered to multiple subscribers.
- SNS-to-SQS fan-out: One topic distributes messages to multiple independent queues.
- Supported destinations: SQS, Lambda, HTTP/HTTPS, email, SMS, and mobile push.
Flashcards
- Q: What is Amazon SNS primarily used for?
A: Managed publish/subscribe messaging and notification delivery to multiple subscribers.
- Q: What is the central resource in SNS?
A: An SNS topic.
- Q: Is SNS push-based or pull-based?
A: Push-based; SNS forwards messages to subscribed endpoints after publication.
- Q: Is SQS push-based or pull-based?
A: Pull-based; consumers poll the queue for messages.
- Q: What is SNS fan-out?
A: Sending one published message to multiple subscribers.
- Q: How can SNS and SQS be combined?
A: Multiple SQS queues can subscribe to one SNS topic, allowing each processing path to receive the same message independently.
- Q: Can one SNS topic deliver to different endpoint types?
A: Yes. A topic can deliver to endpoints such as SQS, Lambda, HTTP/HTTPS, email, SMS, and mobile push.
- Q: What role does SQS play in an SNS fan-out architecture?
A: It provides an independent queue for a consumer or processing workflow.
- Q: What must be configured for SNS-to-SQS delivery to work?
A: The subscription and the required permissions allowing SNS to deliver to the queue.
- Q: When should SNS be selected over SQS alone?
A: When a message must be distributed to multiple subscribers rather than consumed by one queue-processing path.
Practice Questions
Question 1
A company publishes an application event. Three independent applications must receive the event, and each application needs its own queue so it can process messages at its own rate. Which architecture best meets the requirement?
A. Publish directly to one SQS queue and have all applications poll it
B. Publish to an SNS topic with one SQS queue subscribed for each application
C. Have each application poll the SNS topic
D. Send the event directly to one Lambda function
Correct answer: B
Explanation: SNS provides fan-out, and separate SQS queues give each application an independent pull-based processing path. A single SQS queue would not provide the same broadcast behavior to all consumers.
Question 2
A solution must immediately deliver a notification to all subscribed endpoints when a publisher sends a message. Which service and delivery model should the architect choose?
A. Amazon SQS using consumer polling
B. Amazon SNS using push-based delivery
C. Amazon SQS with one consumer reading messages at a time
D. An SQS queue without subscribers
Correct answer: B
Explanation: SNS is designed to push published notifications to all subscribed endpoints. SQS requires consumers to poll the queue.
Question 3
An organization wants the same event delivered to an email audience, an AWS Lambda function, and an application processing queue. Which AWS service should be the distribution point?
A. Amazon SNS topic
B. One SQS queue
C. An EC2 instance acting as a message broker
D. A Lambda function with no subscriptions
Correct answer: A
Explanation: An SNS topic can distribute a message to multiple endpoint types, including email, Lambda, and SQS.
Question 4
An SNS topic is configured with an SQS subscription, but messages are not being delivered to the queue. Which area should be checked first?
A. Whether SQS consumers are pushing messages back to SNS
B. The topic’s email recipient list
C. The SNS subscription and permissions allowing delivery to the queue
D. Whether the queue is configured as an HTTP webhook
Correct answer: C
Explanation: SNS-to-SQS delivery requires a valid subscription and appropriate permissions for SNS to send messages to the queue.