Skip to main content

Amazon SNS

Amazon Simple Notification Service (SNS) is a fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications.

Key Concepts

  • Topics: Communication channels for publishing messages
  • Publishers: Services that send messages to topics
  • Subscribers: Endpoints that receive messages from topics
  • Messages: Up to 256 KB of data in various formats

Subscription Types

EndpointUse Case
LambdaServerless processing
SQSQueue-based processing
HTTP/HTTPSWebhook integrations
EmailNotifications to people
SMSText message alerts
Mobile pushiOS, Android notifications

Common Patterns

Fan-out

One message to multiple consumers:

Publisher → SNS Topic → [SQS Queue 1, SQS Queue 2, Lambda]

Alerting

CloudWatch Alarm → SNS → [Email, SMS, PagerDuty webhook]

Event Broadcasting

Application → SNS → Multiple microservices

Example: Publishing a Message

const sns = new AWS.SNS();
await sns.publish({
TopicArn: 'arn:aws:sns:us-east-1:123456789:my-topic',
Message: JSON.stringify({ event: 'order_placed', orderId: '12345' }),
MessageAttributes: {
eventType: { DataType: 'String', StringValue: 'order_placed' }
}
}).promise();

What We Like

  • Simplicity: Easy to set up and use
  • Fan-out: One publish, many subscribers
  • Durability: Messages are stored across multiple AZs
  • Filtering: Route messages to subscribers based on attributes

What We Don't Like

  • No replay: Messages can't be re-read once consumed (unlike EventBridge)
  • Limited retention: Failed deliveries have limited retry windows
  • Ordering: Standard topics don't guarantee order (FIFO topics do, with limitations)

SNS vs SQS vs EventBridge

FeatureSNSSQSEventBridge
PatternPub/SubQueueEvent bus
ConsumersManyOne (per message)Many
ReplayNoNoYes (archive)
FilteringBasicNoAdvanced