AWS Simple Notification Service (SNS) is a fully managed messaging service that allows applications to send notifications to multiple subscribers via email, SMS, push notifications, or AWS services.
AWS SNS & SQS
What is AWS SNS?
AWS Simple Notification Service (SNS) is a fully managed messaging service that allows applications to send notifications to multiple subscribers via email, SMS, push notifications, or AWS services.
Why Use SNS?
- Allows fan-out architecture (one-to-many message delivery).
- Supports multiple subscribers (Lambda, SQS, Email, SMS, HTTP endpoints).
- Provides high availability and durability.
- Integrates with AWS services like **S3, Lambda, and CloudWatch**.
Creating an SNS Topic
To create an SNS topic and subscribe an email:
aws sns create-topic --name MyTopic
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic --protocol email --notification-endpoint myemail@example.com
aws sns publish --topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic --message "Hello from SNS!"
What is AWS SQS?
AWS Simple Queue Service (SQS) is a fully managed **message queue** service used to decouple and scale applications.
Why Use SQS?
- Ensures **asynchronous communication** between services.
- Supports **standard and FIFO queues**.
- Handles **millions of messages per second**.
- Fully integrates with AWS services like **Lambda, EC2, and SNS**.
Types of SQS Queues
- Standard Queue: Best effort message delivery (unordered).
- FIFO Queue: First-In-First-Out (guarantees order, limited TPS).
Creating an SQS Queue
To create an SQS queue:
aws sqs create-queue --queue-name MyQueue
aws sqs send-message --queue-url QUEUE_URL --message-body "Hello from SQS!"
aws sqs receive-message --queue-url QUEUE_URL
Integrating SNS with SQS
To send SNS messages to an SQS queue:
- Create an SNS topic.
- Create an SQS queue.
- Subscribe the SQS queue to the SNS topic.
- Publish a message to SNS, and SQS will receive it.
aws sns subscribe --topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic \
--protocol sqs --notification-endpoint arn:aws:sqs:us-east-1:123456789012:MyQueue
Use Cases
- Order Processing: E-commerce apps use SQS for order queues.
- Event-Driven Apps: SNS notifies services when an event occurs.
- IoT & Microservices: SNS and SQS connect different services.
Conclusion
Both SNS and SQS provide reliable communication between AWS services. **SNS is for notifications, while SQS is for message queuing**. Combining them improves scalability and decoupling in modern cloud applications.