What is AWS SNS?
AWS Simple Notification Service (SNS) is a fully managed publish/subscribe (pub/sub) messaging service that enables asynchronous communication between applications, microservices, and distributed systems. As a core component of AWS's cloud infrastructure platform, SNS eliminates the operational overhead of managing message broker infrastructure while providing enterprise-grade reliability and scalability.
The pub/sub model fundamentally changes how services communicate. Rather than services calling each other directly (tight coupling), publishers send messages to topics without knowing who will receive them. Subscribers register their interest in specific topics and receive messages automatically. This decoupling enables systems to evolve independently, scale horizontally, and recover from failures more gracefully.
SNS operates on a push-based delivery model, meaning messages are immediately pushed to all subscribed endpoints as soon as they are published. This differs from pull-based systems like Amazon SQS where consumers must actively poll for messages. The push model is ideal for scenarios requiring real-time notification delivery, such as alerting systems, event-driven workflows, and mobile application updates.
As a fully managed service, SNS provides 99.999% availability SLA with automatic replication across multiple availability zones. It supports millions of messages per second with automatic scaling and no capacity planning required. The pay-as-you-go pricing model makes it cost-effective for applications of any scale, from startup prototypes to enterprise production systems.
Enterprise-grade messaging features designed for modern cloud architectures
Pub/Sub Messaging
Decouple publishers from subscribers with topic-based message distribution to millions of endpoints globally.
Multiple Protocols
Deliver messages to HTTP/S, email, SMS, mobile push, SQS queues, Lambda functions, and Kinesis.
Message Filtering
Subscribe to message subsets using policy-based filtering on attributes and payload content.
Message Durability
Automatic replication across multiple availability zones ensures message availability and reliability.
Serverless Integration
Native integration with Lambda, SQS, EventBridge, and other AWS serverless services.
Global Scalability
Process millions of messages per second with automatic scaling and pay-as-you-go pricing.
Understanding Topics and Subscriptions
A topic in SNS serves as a communication channel that groups multiple endpoints for message delivery. When you create a topic, you establish a logical access point through which publishers send messages and subscribers receive them. Topics are regional resources, though SNS can deliver messages globally through cross-region replication. Each topic supports multiple subscriptions, and each subscription can use a different protocol.
This flexibility enables a single published message to simultaneously trigger an AWS Lambda function, add a message to an SQS queue, send an SMS notification, and push content to a mobile application. The fan-out capability is one of SNS's most powerful features for implementing event-driven architectures.
Subscription confirmation is a critical security feature that prevents unauthorized subscriptions. When an endpoint subscribes to a topic (particularly for HTTP, HTTPS, or email protocols), SNS sends a confirmation request. The subscriber must actively confirm by visiting a URL or API call before receiving messages. This prevents malicious actors from subscribing endpoints to topics they don't own.
Subscription Protocols
SNS supports multiple subscription protocols, each serving different use cases and endpoint types:
| Protocol | Use Case | Delivery Method | Considerations |
|---|---|---|---|
| HTTP/HTTPS | Webhooks, web applications | POST request to endpoint | Requires endpoint to confirm subscription; retries on 5xx errors |
| Human notifications, alerts | Email to address | Plain text or JSON format; good for administrative alerts | |
| SMS | Time-sensitive alerts | Text message to mobile | Per-message pricing; ideal for urgent operational alerts |
| Mobile Push | Mobile app engagement | APNs, FCM, ADM | Reach millions of devices through single API call |
| Amazon SQS | Guaranteed processing | Queue storage | At-least-once delivery; ideal for decoupling and buffering |
| AWS Lambda | Serverless processing | Function invocation | Synchronous invocation; automatic retry on failure |
| Kinesis Data Firehose | Data streaming | Direct to data stores | Near-real-time data delivery to S3, Redshift, Elasticsearch |
Standard Topics
Standard topics provide high-throughput, best-effort ordering messaging. They are designed for scenarios requiring massive scale and multicast delivery where message ordering is not critical. Standard topics can deliver messages in a different order than they were published, and in rare cases, may deliver a message more than once.
These topics support all subscription protocols and are ideal for broadcasting events to multiple consumers, decoupling producer and consumer systems, and implementing fan-out patterns requiring horizontal scaling. The performance characteristics are impressive, with the ability to process virtually unlimited messages per second. This makes standard topics suitable for high-traffic applications such as e-commerce order notifications, system alerts, or real-time analytics pipelines.
When using standard topics, applications must be designed to handle potential message duplication idempotently. Occasional message reordering should be acceptable for your use case, or you should implement sequencing logic within your message payloads if order matters.
FIFO Topics
FIFO (First-In-First-Out) topics guarantee strict message ordering and exactly-once processing. Every message is assigned a sequence number, and messages are delivered to subscribers in the precise order they were published. Additionally, FIFO topics prevent duplicate message delivery using message deduplication IDs, ensuring each message is processed exactly once.
FIFO topics integrate specifically with FIFO queues in Amazon SQS, making them ideal for financial transaction processing, inventory management systems, order fulfillment workflows, and any scenario requiring guaranteed message order. The trade-off for these guarantees is a lower throughput limit of 300 messages per second for publishing and subscribing, along with higher pricing.
FIFO topics also have limitations on certain protocols, supporting only SQS FIFO queues and Lambda functions as subscribers. For organizations using multi-cloud strategies, Cloud Pub/Sub on Google Cloud Platform provides similar pub/sub capabilities with its own feature set. Choose FIFO topics when message ordering and deduplication are critical requirements for your application architecture.
| Feature | Standard Topics | FIFO Topics |
|---|---|---|
| Ordering | Best-effort | Strict FIFO |
| Delivery | At-least-once | Exactly-once |
| Throughput | Virtually unlimited | 300 messages/sec |
| Subscribers | All protocols | SQS FIFO, Lambda only |
| Pricing | Base rate | Higher base rate |
| Use Case | Broadcast, fan-out | Ordered processing |
Message Filtering and Attributes
SNS provides sophisticated message filtering capabilities that enable subscribers to receive only the messages relevant to their interests. This filtering happens at the subscription level, reducing unnecessary message processing and network traffic for endpoints that don't need certain messages.
Message Attributes
Message attributes are structured metadata that publishers attach to messages. Each message can have up to 10 attributes, each with a name, type (String, Number, Binary), and value. Attributes provide structured context about the message that subscribers can use for filtering or processing decisions.
{
"MessageAttributes": {
"order_type": {
"DataType": "String",
"StringValue": "standard"
},
"total_amount": {
"DataType": "Number",
"StringValue": "150.00"
},
"shipping_country": {
"DataType": "String",
"StringValue": "US"
},
"contains_fragile_items": {
"DataType": "String",
"StringValue": "true"
}
}
}
Filter Policies
Filter policies are JSON documents that define conditions for message delivery. When a subscription has a filter policy, SNS evaluates message attributes against the policy conditions. Only messages matching the policy are delivered.
{
"filterPolicy": {
"region": ["us-west-2", "us-east-1"],
"priority": ["high", "urgent"],
"order_value": {
"numeric": [">=", 100]
}
}
}
For example, consider a multi-region application where a "ConfigUpdated" event has a region attribute. The us-west-2 subscription uses a filter policy {"region": ["us-west-2"]}, while eu-central-1 uses {"region": ["eu-central-1"]}. Each region receives only its relevant configuration updates, reducing unnecessary processing and ensuring regional data sovereignty compliance.
Delivery Mechanisms and Retry Policies
SNS provides robust message delivery with automatic retry mechanisms and configurable failure handling. Understanding these mechanisms is essential for building reliable systems.
Retry Policies
When SNS delivers a message to a subscription endpoint and delivery fails, SNS enters a retry phase. The retry policy is configurable with minimum and maximum retry delays, retry backoff function (linear or exponential), and maximum retry attempts before giving up.
For HTTP/HTTPS endpoints, SNS retries with exponential backoff starting from 1 second and doubling up to a maximum of 512 seconds. The typical retry timeline follows this pattern: attempt 1 at 1 second, attempt 2 at 2 seconds, attempt 3 at 4 seconds, attempt 4 at 8 seconds, and so on until reaching 512 seconds. After approximately 3 hours of retries, messages that still cannot be delivered may be routed to a dead letter queue.
Dead Letter Queues
Dead letter queues (DLQs) are essential for handling messages that cannot be delivered after all retry attempts are exhausted. Rather than losing these messages, SNS moves them to an SQS queue where administrators can inspect, debug, and manually reprocess them. Configuring a DLQ for each subscription is a best practice for production systems.
Without a DLQ, failed messages are lost with no visibility into failure patterns. The DLQ provides an audit trail and ensures no message is silently dropped. When configuring DLQs, set up CloudWatch alarms to alert your team when messages arrive in the DLQ, indicating potential issues with subscribers or upstream systems that require investigation.
Security Best Practices
Access Control with IAM
AWS Identity and Access Management (IAM) policies control who can publish to topics, subscribe to topics, and manage topic configurations. The principle of least privilege should guide all access grants--users and roles should receive only the permissions necessary for their functions.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["sns:Publish"],
"Resource": "arn:aws:sns:us-east-1:123456789012:orders-events"
},
{
"Effect": "Allow",
"Action": ["sns:Subscribe", "sns:ListSubscriptionsByTopic"],
"Resource": "arn:aws:sns:us-east-1:123456789012:orders-events"
}
]
}
A well-designed access strategy separates concerns: publishers need only sns:Publish permission on specific topics, subscribers need sns:Subscribe and potentially sns:Unsubscribe, and administrators manage topic lifecycle and policies.
Encryption
SNS supports server-side encryption (SSE) using AWS Key Management Service (KMS) keys. When enabled, all messages stored in SNS are encrypted at rest using customer-managed or AWS-managed keys. SSE is particularly important for topics handling sensitive data such as personal information, financial details, or health records.
VPC Endpoints
For applications running within an Amazon VPC, VPC endpoints provide private connectivity to SNS without traversing the public internet. This is essential for workloads requiring strict network isolation or operating in regulated environments. VPC endpoints can be configured with endpoint policies that restrict which topics can be accessed through the endpoint.
Subscription Authentication
The AuthenticateOnUnsubscribe parameter, set during subscription confirmation, requires authentication for subsequent unsubscribe requests, preventing malicious removal of legitimate subscribers. This prevents unauthorized removal of subscriptions and should be enabled for all production topics.
Integration with AWS Services
SNS integrates deeply with other AWS services, enabling powerful event-driven architectures without custom integration code. These integrations form the backbone of modern serverless applications on AWS.
AWS Lambda
Lambda is the most common subscriber type for serverless applications. When a message is published to an SNS topic with a Lambda subscription, SNS invokes the Lambda function synchronously, passing the message as the event payload.
exports.handler = async (event) => {
for (const record of event.Records) {
const message = record.Sns;
console.log(`Message: ${message.Message}`);
console.log(`Subject: ${message.Subject}`);
console.log(`Attributes: ${JSON.stringify(message.MessageAttributes)}`);
// Process the message
await processNotification(message);
}
return { statusCode: 200, body: 'Processed' };
};
Amazon SQS
SQS queues serve as reliable subscribers that buffer messages for asynchronous processing. The SNS-to-SQS fan-out pattern is foundational for implementing parallel processing, where a single SNS topic distributes messages to multiple SQS queues for different consumers.
Amazon EventBridge
EventBridge can serve as both a consumer and producer of SNS messages. SNS topics can be event targets, receiving events from EventBridge rules. Conversely, SNS can publish events to EventBridge, enabling integration with the EventBridge event bus for sophisticated routing, cross-account event sharing, and integration with SaaS event sources.
Amazon CloudWatch
CloudWatch provides monitoring and observability for SNS with metrics including message publish counts, delivery success and failure rates, publishing latency, and notification size. CloudWatch Alarms can be configured to trigger notifications when thresholds are exceeded, enabling proactive monitoring of message delivery health.
Common Use Cases
Application Alerting and Monitoring
SNS delivers critical notifications about system health, security events, and performance anomalies through multiple channels. When CloudWatch detects a metric threshold breach, it can publish to an SNS topic that distributes alerts through SMS for urgent issues, email for standard alerts, and mobile push for on-call engineers.
Example: A financial services company uses SNS to send SMS alerts when API latency exceeds 500ms, email notifications for failed login attempts, and mobile push notifications for high-severity security events.
Mobile Application Notifications
Mobile push notifications powered by SNS enable applications to engage users with time-sensitive information. Whether delivering breaking news, order status updates, or promotional offers, SNS provides the infrastructure to reach millions of mobile devices through a single API call using APNs, FCM, and ADM.
Distributed System Decoupling
In microservices architectures, SNS serves as the backbone for inter-service communication, enabling truly decoupled systems. Rather than services calling each other directly, they communicate through events published to SNS topics. This loose coupling enables independent deployment of services, horizontal scaling of individual components, failure isolation between services, and introduction of new consumers without impacting publishers.
Example: An e-commerce platform publishes "OrderCreated" events to SNS. The payment service, inventory service, notification service, and analytics service all subscribe to this topic. Each service processes the order information independently. If the analytics service experiences issues, orders continue to flow to payment and inventory systems without interruption.
Data Pipeline Integration
SNS can initiate data processing pipelines by triggering Lambda functions or adding messages to SQS queues. When new data arrives in S3 or a database, an event notification published to SNS can kick off ETL workflows, analytics calculations, or data synchronization processes.
Best Practices Summary
Naming and Organization
Adopt consistent naming conventions for SNS topics that reflect their purpose, environment, and data classification. Topics should be named descriptively (e.g., prod-orders-events, dev-security-alerts) and organized to facilitate access control and monitoring.
Monitoring and Observability
Implement comprehensive monitoring for all production topics: configure CloudWatch alarms for delivery failures, use CloudWatch Logs Insights to analyze message content, set up notification workflows for operational anomalies, and conduct regular review of dead letter queue contents.
Error Handling Strategy
Design robust error handling that accounts for automatic retry with exponential backoff, dead letter queue configuration for all subscriptions, alerting on messages entering dead letter queues, and regular analysis and remediation of failed messages.
Cost Optimization
Optimize SNS costs by using message batching for high-volume scenarios, implementing message filtering to reduce unnecessary deliveries, choosing appropriate delivery protocols for each use case, and monitoring and right-sizing notification frequency.
Limitations
- 256KB message size limit: Larger payloads require reference patterns (S3 + SNS reference)
- Regional topics: Topics are regional resources requiring additional consideration for global applications
- Standard topic delivery: At-least-once delivery means applications must handle duplicate messages idempotently
Frequently Asked Questions
AWS SQS
Learn about Amazon Simple Queue Service for message queuing and guaranteed processing.
Learn moreEvent-Driven Architecture
Explore patterns for building responsive, decoupled systems with event-driven patterns.
Learn moreCloud Infrastructure Services
Discover our comprehensive cloud infrastructure services and solutions.
Learn more