You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Amazon Simple Notification Service (SNS) is a fully managed publish-subscribe (pub/sub) messaging service. While SQS provides point-to-point messaging (one producer, one consumer), SNS enables one-to-many communication — a single message published to a topic is delivered to multiple subscribers simultaneously.
| Feature | SQS (Queue) | SNS (Topic) |
|---|---|---|
| Pattern | Point-to-point | Publish-subscribe |
| Consumers | One consumer per message | Multiple subscribers per message |
| Delivery | Consumer polls the queue | SNS pushes to subscribers |
| Persistence | Messages stored until deleted | No persistence — push and forget |
| Use case | Work queues, task processing | Notifications, fan-out, broadcasting |
Publisher ——> [SNS Topic] ——> Subscriber 1 (Email)
——> Subscriber 2 (SQS Queue)
——> Subscriber 3 (Lambda Function)
——> Subscriber 4 (HTTP Endpoint)
| Feature | Standard Topic | FIFO Topic |
|---|---|---|
| Throughput | Nearly unlimited | 300 msg/s (3,000 with batching) |
| Ordering | Best-effort | Strict |
| Delivery | At-least-once | Exactly-once |
| Subscribers | All types | SQS FIFO only |
| Topic name | Any valid name | Must end in .fifo |
SNS can push messages to a wide variety of endpoints:
| Subscriber Type | Description | Use Case |
|---|---|---|
| Amazon SQS | Deliver to an SQS queue | Decoupled processing, fan-out |
| AWS Lambda | Invoke a Lambda function | Serverless event processing |
| HTTP/HTTPS | POST to a webhook URL | Third-party integrations |
| Send an email (requires confirmation) | Alerts, notifications | |
| SMS | Send a text message | Urgent notifications |
| Mobile push | Push notification (APNs, FCM) | Mobile app alerts |
| Amazon Kinesis Data Firehose | Stream to S3, Redshift, etc. | Data archiving |
import boto3
sns = boto3.client('sns')
sns.publish(
TopicArn='arn:aws:sns:eu-west-2:123456789012:order-events',
Subject='New Order',
Message='{"orderId": "ORD-12345", "status": "placed", "total": 49.99}'
)
Message attributes are metadata attached to the message. They are critical for message filtering (covered below).
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.