What Is Amazon SNS? Learn the Basics and How to Publish Messages to a Topic
There are many situations where you need to deliver events or notifications between applications in real time. Amazon SNS is a fully managed notification service that makes it easy to implement the fan-out pattern — sending a single message to multiple destinations at once. This article covers the core concepts of SNS and walks you through creating a topic and publishing messages using the AWS CLI.
What Is Amazon SNS
Amazon SNS (Simple Notification Service) is a fully managed pub/sub messaging service provided by AWS. When a publisher sends a message to a topic, that message is delivered to all subscribers of that topic. There's no need to manage servers or poll a message queue, making it straightforward to build event-driven architectures at low cost.
Common use cases include sending alerts from applications, delivering events between microservices, and building serverless workflows with Lambda and SQS.
What is Amazon SNS? - Amazon Simple Notification Service
This topic provides an introduction to Amazon SNS and how it facilitates asynchronous message delive...
Topic Types
SNS topics come in two types: Standard and FIFO. Choose based on your use case.
| Type | Ordering | Deduplication | Throughput |
|---|---|---|---|
| Standard | None (best-effort) | None (duplicate delivery possible) | Nearly unlimited |
| FIFO | Yes (delivered in send order) | Yes (controlled via deduplication ID) | Up to 300 msg/sec (3,000 msg/sec with batching) |
Use FIFO topics when ordering or deduplication matters. For high-throughput scenarios like log collection or alert notifications, Standard topics are the better fit.
Message ordering and deduplication strategies using Amazon SNS FIFO topics - Amazon Simple Notification Service
Learn how Amazon SNS FIFO (first in, first out) topics can be used with Amazon SQS FIFO queues to en...
Supported Subscription Protocols
SNS supports message delivery to a wide range of destinations. You can register multiple subscriptions with different protocols on a single topic, and all of them receive the message when it's published.
| Protocol | Destination | Common Use Cases |
|---|---|---|
| Email / Email-JSON | Email address | Human notifications and alerts |
| HTTP / HTTPS | Web endpoint | Webhooks to external services |
| SQS | SQS queue | Async processing and message buffering |
| Lambda | Lambda function | Serverless event processing |
| SMS | Mobile phone number | SMS notifications |
| Application | Mobile push notification endpoint | Push notifications to iOS / Android |
| Firehose | Amazon Data Firehose | Log and data streaming |
Subscribe - Amazon Simple Notification Service
Subscribes an endpoint to an Amazon SNS topic. If the endpoint type is HTTP/S or email, or if the en...
Try SNS with the AWS CLI
Let's walk through creating a topic, registering an email address as a subscription, and publishing a message using the AWS CLI.
Create a Topic
Start by creating a topic, which is the destination for your messages. The name you pass to --name becomes the topic name.
❯ aws sns create-topic --name exrecord-topic
{
"TopicArn": "arn:aws:sns:us-east-1:123456789012:exrecord-topic"
}
Save the topic ARN returned here — you'll need it when registering subscriptions and publishing messages.
Register a Subscription
Next, register an email address as a subscriber to the topic. Pass email to --protocol and the recipient address to --notification-endpoint.
❯ aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789012:exrecord-topic \
--protocol email \
--notification-endpoint you@example.com
{
"SubscriptionArn": "pending confirmation"
}
Right after registration, the status is pending confirmation. A confirmation email will be sent to the specified address — click the "Confirm subscription" link in that email to activate the subscription.
Once confirmed, you can check the subscription status with the following command.
❯ aws sns list-subscriptions-by-topic \
--topic-arn arn:aws:sns:us-east-1:123456789012:exrecord-topic
{
"Subscriptions": [
{
"SubscriptionArn": "arn:aws:sns:us-east-1:123456789012:exrecord-topic:0a1b2c3d-4e5f-6789-abcd-0a1b2c3d4e5f",
"Owner": "123456789012",
"Protocol": "email",
"Endpoint": "you@example.com",
"TopicArn": "arn:aws:sns:us-east-1:123456789012:exrecord-topic"
}
]
}
When the SubscriptionArn shows a full ARN instead of PendingConfirmation, the subscription is confirmed.
Publish a Message
Publishing a message to the topic delivers it to all registered subscribers. Pass the message body to --message.
❯ aws sns publish \
--topic-arn arn:aws:sns:us-east-1:123456789012:exrecord-topic \
--subject "Test Notification" \
--message "This is a test message from SNS."
{
"MessageId": "0a1b2c3d-4e5f-6789-abcd-0a1b2c3d4e5f"
}
A successful publish returns a MessageId. Wait a moment and the notification should arrive at the registered email address.
Delete a Subscription
You can delete a subscription when it's no longer needed. Pass the target subscription ARN to --subscription-arn.
❯ aws sns unsubscribe \
--subscription-arn arn:aws:sns:us-east-1:123456789012:exrecord-topic:0a1b2c3d-4e5f-6789-abcd-0a1b2c3d4e5f
Delete a Topic
Delete the topic when you're done with it. Deleting a topic also removes all of its subscriptions.
❯ aws sns delete-topic \
--topic-arn arn:aws:sns:us-east-1:123456789012:exrecord-topic
Summary
This article covered the core concepts of Amazon SNS and how to create a topic, register a subscription, and publish messages using the AWS CLI.
- SNS is a fully managed pub/sub messaging service that makes it easy to implement the fan-out pattern — delivering a single message to multiple destinations at once
- Topics come in two types — Standard (high throughput) and FIFO (ordered delivery with deduplication) — choose based on your use case
- You can register diverse protocols like Email, SQS, Lambda, and SMS as subscriptions, and combine multiple protocols on a single topic
- Publishing a message with the
sns publishcommand delivers it to all registered subscribers in real time - Combining SNS with SQS enables message buffering and reprocessing, helping you build more resilient architectures