What Is SNS?
Amazon SNS (Simple Notification Service) is a pub/sub messaging service. You publish a message to a topic, and all subscribers receive it. Subscribers can be SQS queues, Lambda functions, HTTP endpoints, email addresses, or SMS numbers.
The core pattern: one event, many consumers. A single publish call fans out to however many subscribers are on the topic.
When to Use SNS
Good fit:
- Fan-out to multiple independent consumers
- Notifications (email, SMS, push)
- Decoupling services that don't need content-based routing
- Cross-account/cross-region event delivery
Use EventBridge instead when:
- You need content-based routing (match on fields inside the message body)
- You need to route to 30+ different targets with different rules
- You're working with AWS service events (EventBridge gets them natively)
- You need schema registry and event replay
Use SQS directly when:
- You have a single consumer that processes at its own pace
- You need strict ordering (FIFO)
- You need exactly-once processing
SNS + SQS: The Fan-Out Pattern
The most common production pattern: SNS fans out to multiple SQS queues, each consumed independently.
Producer β SNS Topic β SQS Queue A (order fulfillment)
β SQS Queue B (analytics)
β SQS Queue C (notifications)
β Lambda (real-time processing)
Why not subscribe Lambda directly to SNS? You can. But you lose the buffering and retry that SQS provides. If Lambda throttles or fails, SNS retries for a while then gives up. With SQS in between, messages are retained until successfully processed.
Message Filtering
Subscribers can filter messages by attributes, so they only receive messages they care about:
Publisher sets attributes:
{
"Type": "OrderPlaced",
"Amount": 1500,
"Region": "us-east-1",
"Priority": "high"
}
Subscriber filter policy:
{
"Priority": ["high"],
"Amount": [{"numeric": [">", 1000]}]
}
This subscriber only receives messages where Priority is "high" AND Amount > 1000. All other messages are filtered out. No cost for the subscriber, no unnecessary processing.
Message Types
Standard topics
- Unlimited throughput
- At-least-once delivery
- Best-effort ordering
- Use for: most pub/sub use cases
FIFO topics
- 300 messages/second (3,000 with batching)
- Exactly-once delivery
- Strict ordering within message group
- Can only deliver to FIFO SQS queues and Lambda
- Use for: financial transactions, ordered event streams
CDK Example
import { Topic } from 'aws-cdk-lib/aws-sns';
import { SqsSubscription, LambdaSubscription } from 'aws-cdk-lib/aws-sns-subscriptions';
const orderTopic = new Topic(this, 'OrderEvents', {
topicName: 'order-events',
});
// Fan-out to multiple queues with filtering
orderTopic.addSubscription(new SqsSubscription(fulfillmentQueue, {
filterPolicy: {
eventType: SubscriptionFilter.stringFilter({ allowlist: ['OrderPlaced'] }),
},
}));
orderTopic.addSubscription(new SqsSubscription(analyticsQueue));
orderTopic.addSubscription(new LambdaSubscription(notificationFn, {
filterPolicy: {
priority: SubscriptionFilter.stringFilter({ allowlist: ['high'] }),
},
}));
// Grant publisher
orderTopic.grantPublish(apiFunction);
Cross-Account and Cross-Region
SNS supports cross-account subscriptions via resource policies and cross-region delivery to SQS/Lambda. This makes it useful for:
- Central event topics that multiple accounts subscribe to
- Replicating events across regions for disaster recovery
- Shared notification systems in multi-account organizations
Cost
- $0.50 per million publishes
- Deliveries to SQS/Lambda: free
- Deliveries to HTTP: $0.06 per 100,000
- SMS: varies by country ($0.00645/message US)
- Message filtering: no additional cost
The publish cost is the main charge. SQS and Lambda deliveries are free on the SNS side (you still pay for SQS requests and Lambda invocations).
Further Reading
Looking for hands-on help? View my AWS architecture services β