SNS — Concept
What it is
Amazon Simple Notification Service (SNS) = managed pub/sub messaging. Publishers push to a topic; SNS fans out to all subscriptions in parallel.
Why it exists
You want one event to reach many consumers (a queue, a Lambda, email, SMS, HTTPS endpoint) without each publisher knowing about each subscriber.
Subscriber types
- SQS queues (most common; reliable fanout)
- Lambda functions
- HTTP / HTTPS endpoints
- Email / Email-JSON
- SMS (text messages)
- Mobile push (APNS, FCM, ADM)
- Kinesis Data Firehose (for analytics fanout)
- EventBridge event bus (for cross-account routing)
Topic types
| Standard topic | FIFO topic | |
|---|---|---|
| Order | best-effort | strict per group |
| Delivery | at-least-once | exactly-once |
| Subscribers | many types | SQS FIFO only |
| Use | broad fanout | ordered fanout |
Filtering
- Subscription filter policies (JSON) on message attributes — subscriber only gets messages matching the filter. Reduces app-side filtering and SQS message volume.
Delivery & retries
- For HTTP/HTTPS: configurable retry policy.
- For SQS / Lambda: handled by those services.
- Failed deliveries can go to DLQ per subscription.
Security
- Topic policy (resource-based) for cross-account access.
- KMS encryption at rest.
- VPC endpoint (Interface) for private access.
Common patterns
- Fanout: SNS → multiple SQS queues (one per downstream service).
- Workflow notification: alarm → SNS → Lambda + email + Slack via HTTPS.
- CloudWatch Alarms publish to SNS topics for paging.
- Mobile push notifications.
When to use vs alternatives
| Use ... | Instead of ... | When ... |
|---|---|---|
| SNS → SQS fanout | Direct producer-to-many | Fanout one event to many durable queues |
| EventBridge | SNS | Event router with rich filtering, archive, replay, cross-account |
| SQS | SNS | Single consumer queue (decoupling) |
| Kinesis | SNS | Streaming analytics with multiple long-lived consumers |
| Step Functions | SNS | Orchestrate multi-step workflows |
Common exam scenarios
- "Send one event to email + Lambda + SQS reliably" → SNS topic with 3 subscribers.
- "Fanout with filters to different queues" → SNS + subscription filter policies.
- "FIFO ordering across fanout" → SNS FIFO topic + SQS FIFO subscribers.
- "Cross-account event routing with rich filtering, replay, archive" → EventBridge, not SNS.
- "Publish mobile push to iOS + Android" → SNS with platform endpoints.
Exam tip
- One-to-many ≈ SNS.
- Many-to-one ≈ SQS.
- Cross-AWS-service routing & filters ≈ EventBridge.