AWS SNS
Amazon Simple Notification Service (SNS) is a fully managed messaging service for publish/subscribe: a publisher sends a message to a topic and SNS delivers a copy to every subscriber.
Key concepts #
- Topic: the channel. Standard topics offer very high throughput and at-least-once delivery; FIFO topics keep the order and deduplicate.
- Subscription protocols: SQS queues, Lambda functions, HTTP/S endpoints, email, SMS, mobile push and Amazon Data Firehose.
- Fan-out: one message reaches several systems, for example a topic that delivers to three SQS queues, each processed by a different service.
- Message filtering: a subscription filter policy receives only the messages whose attributes match.
- Delivery retries and dead-letter queues handle failed deliveries.
- Encryption at rest with KMS and access control with IAM and topic policies.
- Many AWS services publish to SNS, notably CloudWatch alarms and Auto Scaling notifications.
SNS or SQS? #
SNS pushes a message to many subscribers; SQS stores messages in a queue until a consumer pulls them. They are often combined.
Pricing #
Per million publishes and per delivery, which depends on the protocol (SMS has additional per-message costs by country). See the SNS pricing.
With Terraform #
The resources are aws_sns_topic, aws_sns_topic_subscription and aws_sns_topic_policy.