SkillSprout
Chapter 9 · Lesson 2
Intermediate
7 min read

SNS

Overview

Amazon Simple Notification Service (SNS) is a fully managed publish/subscribe (pub/sub) messaging service. A publisher sends one message to a topic, and SNS pushes a copy to every subscriber of that topic: Lambda functions, SQS queues, HTTP endpoints, email addresses, SMS numbers, mobile push and more.

Compare SNS with a newspaper delivery service. The publisher prints one edition; the delivery service makes sure each subscriber gets a copy at their own door in the format they prefer. The publisher never needs to know who the subscribers are or how many exist.

SNS is the standard building block for fan-out, alerting (CloudWatch alarms, budgets, Auto Scaling events) and event notification. It shows up on the SAA-C03 exam both on its own and paired with SQS and Lambda.

Key Concepts

  • SNS is push-based pub/sub: publishers send to a topic, and SNS delivers to all subscriptions.
  • Subscription protocols: SQS, Lambda, HTTP/HTTPS, email/email-JSON, SMS, mobile push (APNs, FCM), and Kinesis Data Firehose.
  • Standard topics offer best-effort ordering and at-least-once delivery; FIFO topics add strict ordering and deduplication.
  • Fan-out pattern: one SNS topic -> many SQS queues for parallel, independent, durable processing.
  • Subscription filter policies let each subscriber receive only the messages matching message attributes or body content.
  • Messages are limited to 256 KB; larger payloads use the Extended Client Library with S3.
  • Delivery to failing endpoints is retried, and a per-subscription DLQ (an SQS queue) captures undeliverable messages.
  • Topics support SSE with KMS, access policies, and cross-account / cross-region subscriptions.

Detailed Notes

Topics, publishers and subscribers

A topic is a logical access point and communication channel. Publishers call Publish (up to 256 KB, or batch up to 10). SNS stores the message across multiple AZs, then delivers to each subscription. Subscribers must confirm subscriptions for email, HTTP/S and SMS endpoints; SQS and Lambda subscriptions in the same account are confirmed automatically.

Limit / factValue
Max message size256 KB
Topics per account (default)100,000
Subscriptions per topicup to 12,500,000
Delivery modelPush
ProtocolsSQS, Lambda, HTTP(S), email, SMS, mobile push, Firehose

Standard vs. FIFO topics

  • Standard: very high throughput, at-least-once, best-effort ordering. Supports all protocols.
  • FIFO: strict ordering using MessageGroupId, deduplication (5-minute window), message archiving and replay. Subscribers are mainly SQS queues (FIFO or standard); email, SMS and mobile push are not supported. Names end in .fifo.

The fan-out pattern

Publishing to one topic with several SQS subscribers means every queue gets its own copy. Each downstream system (billing, shipping, analytics) processes at its own speed and retries independently. This is more reliable than the publisher calling each system, and adding a new consumer needs no change to the producer.

text
Order service -> SNS "orders" -> SQS billing   -> billing workers
                              -> SQS shipping  -> shipping workers
                              -> Lambda audit
                              -> Firehose -> S3 data lake

The SQS queue's access policy must allow sns.amazonaws.com to send messages (see the SQS lesson).

Message filtering

By default every subscriber gets every message. A filter policy (JSON, attached to the subscription) restricts delivery. Filtering runs on message attributes (default) or the message body.

json
{
  "store": ["eu-west"],
  "event": [{ "anything-but": "order_cancelled" }],
  "price_usd": [{ "numeric": [">=", 100] }]
}

Reliability and delivery

  • SNS retries failed deliveries using a delivery policy (HTTP/S has configurable retries; Lambda and SQS have retries over many hours).
  • Attach a dead-letter queue to a subscription so undeliverable messages are kept rather than dropped.
  • Enable delivery status logging to CloudWatch Logs for SMS, Lambda, SQS, HTTP and mobile push.
  • Topic archiving and replay is available for FIFO topics.

Security

  • Topic access policy (resource policy) for cross-account publishing/subscribing and to allow AWS services (S3, CloudWatch, Budgets) to publish.
  • SSE with KMS to encrypt at rest; HTTPS to encrypt in transit; VPC interface endpoints for private publishing.
  • IAM controls who can sns:Publish and sns:Subscribe.

Mobile push and SMS

SNS can send mobile push notifications via APNs, FCM and others through platform applications, and SMS to phones worldwide. SMS is subject to spending limits and country regulation (registration for A2P messaging).

SNS vs. SQS vs. EventBridge

SNSSQSEventBridge
ModelPush pub/subPull queueEvent bus with rules
ConsumersMany (all subscribers)One per messageMany targets per rule
PersistenceNot stored after deliveryUp to 14 daysArchive/replay optional
FilteringFilter policiesNoneRich content patterns

Real World Example

Scenario — an e-commerce platform processes a new order.

When a customer pays, the order service publishes a single OrderPlaced message to an SNS topic. Four consumers need it, each with different speed and reliability needs:

  • An SQS queue feeds the shipping workers, which are slow and sometimes throttled by a courier API.
  • A second SQS queue feeds the invoicing service, which must never lose an order.
  • A Lambda function sends the customer a confirmation email through Amazon SES.
  • Kinesis Data Firehose streams every order to S3 for analytics.

The fraud team subscribes with a filter policy (price_usd >= 1000) so they only see high-value orders. If the courier API is down, the shipping queue simply grows, and nothing is lost. When a new loyalty-points service is added next quarter, the team just adds a subscription; the order service code is untouched. The pattern cut order-processing incidents dramatically because services no longer fail together.

Architecture Diagram

SNS fan-out to SQS, Lambda and Firehose
Architecture
AWS Cloud
API Gatewaypublisher
SNS topicorders
Shipping queue
Shipping workers
Invoice queue
Invoice function
Email function
Data lakevia Firehose

One publish, many independent subscribers, filtered per subscription.

  1. 1The order service publishes one message to the SNS topic.
  2. 2SNS applies each subscription's filter policy and pushes copies to matching subscribers in parallel.
  3. 3SQS queues store their copy durably until the workers consume it.
  4. 4Lambda and Firehose subscribers are invoked immediately; failed deliveries are retried and then sent to a subscription DLQ.

Best Practices

  • ✓Pair SNS with SQS for durable fan-out so slow or failed consumers never block others.
  • ✓Use filter policies instead of making consumers discard unwanted messages; it cuts cost and code.
  • ✓Add a DLQ to important subscriptions and alarm on NumberOfNotificationsFailed.
  • ✓Secure topics with least-privilege topic policies and SSE-KMS; scope service principals with aws:SourceArn / aws:SourceAccount.
  • ✓Use FIFO topics + FIFO queues only when ordering or dedup matter; keep standard otherwise for throughput.
  • ✓Keep payloads small (IDs, not documents); store large data in S3 and send a reference.
  • ✓Enable delivery status logging to troubleshoot subscriber failures.
  • ✓Make subscribers idempotent; SNS standard topics can deliver duplicates.

Common Interview Questions

Exam Tips

SAA-C03 focus

  • "Send one message to multiple consumers" or "fan-out" -> SNS (usually with SQS subscribers).
  • SNS is push; SQS is pull. SNS does not persist messages for later retrieval.
  • Email, SMS and mobile push notifications for alarms -> SNS. CloudWatch alarms, Budgets and Auto Scaling notifications all publish to SNS.
  • Only some subscribers need some events -> subscription filter policy.
  • Ordered, de-duplicated fan-out -> SNS FIFO topic with SQS FIFO queues.
  • S3 event notifications can target SNS, SQS or Lambda (and EventBridge for richer routing).
  • SNS message size limit is 256 KB; larger -> store in S3 and send the link.
  • Cross-account delivery needs a topic policy (and queue policy for SQS subscribers).

Finished this lesson?

0 of 64 lessons done · 0% of the course