1.SNS Topics, Subscriptions, Filtering, and Fan-Out
A topic is a named channel a publisher sends messages to, without knowing who — if anyone — is listening. A subscription attaches one delivery target (SQS, Lambda, HTTP(S), email, SMS, mobile push) to a topic; every subscription gets its own copy of each message. A filter policy on a subscription drops messages that do not match, so one topic can serve subscribers that each want a different subset. Fan-out is what happens when a topic has multiple subscriptions: one publish reaches every matching subscriber in parallel.
Key features
- Delivery targets: Amazon SQS, AWS Lambda, HTTP(S) endpoints, email, SMS, mobile push, Amazon Data Firehose, and select third-party service providers
- A filter policy is JSON attached to a subscription; without one, that subscriber receives every message published to the topic
- Filter policies match on message attributes or the message body (body matching requires the payload to be well-formed JSON)
- Server-side delivery failures retry on a per-protocol schedule: SQS/Lambda get up to 100,015 attempts over 23 days; SMTP/SMS/mobile push get up to 50 attempts over 6 hours
- Client-side errors (e.g. the subscribed endpoint was deleted) are not retried at all — SNS discards the message immediately unless a dead-letter queue is attached
- A dead-letter queue is attached per subscription, not per topic — because delivery, and delivery failure, happens at the subscription level
- Publisher
- leads to SNS topic (Publish(message))
- SNS topic
- leads to SQS subscriber (matches filter)
- leads to Lambda subscriber (matches filter)
- leads to Email subscriber (no filter — gets everything)
- SQS subscriber
- Lambda subscriber
- Email subscriber
Signature
Topic → N subscriptions (SQS | Lambda | HTTP(S) | email | SMS | push | Firehose), each with an optional filter policy and optional DLQ
Topic = named channel; subscription = one delivery target attached to it, each with its own filter policy and retry schedule. Fan-out is one publish reaching every matching subscriber in parallel. Client-side errors are not retried; server-side errors retry per-protocol (SQS/Lambda: ~23 days; SMTP/SMS/push: ~6 hours) before being discarded — attach a DLQ per subscription to catch what would otherwise be lost.