Amazon SNS is a service for sending push notifications from an application to the end user or other programs.
It’s a comprehensive messaging service that enables communication between applications (Aapplication To Aapplication – A2A) or persons (Aapplication To Person – A2B). It allows you to create topics (i.e. subjects) that will be the logical access and communication channel.
SNS uses the pub/sub paradigm (publish / subscribe) for message delivery. This principle establishes that publishers (publishers) send messages via common communication channels called “topic” (topic), while subscribers (subscribers) automatically receive messages corresponding to the topics for which they are subscribed.
We can visualize the topics as a virtual “mailbox” that allows individual subscribers to retrieve messages without having to communicate directly with the editors. In this way, each subscriber can specify the types of messages they wish to receive, via their various subscriptions.
![](https://datascientest.com/wp-content/uploads/2023/03/image4-5.png)
Definition of important terminology
It’s important to understand certain terms related to messaging services before proceeding. The table below will help you understand these key terms:
Term | Description |
---|---|
Publisher![]() |
|
Subscriber![]() |
|
Topic![]() |
|
The diagram below perfectly illustrates the elements provided above:
![](https://datascientest.com/wp-content/uploads/2023/03/image8-1.png)
What are the features of AWS SNS?
Here are some of the key features of AWS SNS:
- Scaling: the service automatically adapts to growing message volume requirements.
- Message encryption: message protection is a priority SNS protects all messages according to encryption models. They are automatically decrypted once transmitted to the recipient’s endpoint.
- Message filtering: the subscriber can change the filtering policy to receive only relevant notifications.
- Replication: when a message is sent to a topic, it is replicated on several endpoints.
- Mobile notification: actions from the application (initiated by your users) or from cloud-based business logic can be triggered
- Email: Amazon SNS can send mail messages (SMTP)
Comparison between SNS and SQS
These are two messaging services offered by Amazon Web Services. The table below will help you understand the differences:
Feature | Amazon SNS![]() |
Amazon SQS![]() |
---|---|---|
Model | Pub / Sub | Queue |
Primary Use | Sending messages and notifications to multiple recipients | Queue management for message delivery |
Distribution | All subscribers receive messages | Messages are consumed by one consumer at a time |
Communication Protocols | HTTP, HTTPS, email, SMS, mobile, push, etc. | Amazon SQS, HTTP, HTTPS |
Message Format | JSON, XML, plain text, etc. | JSON, XML, plain text, etc. |
Message Processing | No built-in processing, but can be coupled with Amazon AWS Lambda | Built-in processing via customizable processing workers |
Capacity Management | Dynamically adjustable | Managed by the number of workers and the number of queues |
In short, Amazon SNS is designed to send messages to multiple recipients via a pub/sub messaging model, while Amazon SQS is designed to manage message queues, with a FIFO (first-in, first-out) messaging model.
![](https://datascientest.com/wp-content/uploads/2023/03/image10-1.png)
They can be used together to create a complex, highly scalable messaging architecture.
As we have just seen, SNS enables a message to be published to different supported endpoints. When an SQS queue subscribes to an SNS topic, every message sent by that SNS topic joins the queue, along with the message body and its various attributes.
The message is then almost guaranteed to be correctly distributed. “Almost”, because the SQS queue may be unavailable. In this case, Amazon SNS will make new attempts (exactly 100,010 attempts over 23 days) before the message is deleted.
If your queue is unavailable for such a long time, you most likely have a problem with your messaging infrastructure.
For more information on Amazon SQS, read our article on the subject.
How can I integrate AWS SNS?
As you probably know, one of the great strengths of Amazon AWS is the possible integration and joint operation between its various services. SNS is no exception to this rule, and can be easily integrated with different AWS services to create a complete system. Here are a few examples of possible integrations.
![](https://datascientest.com/wp-content/uploads/2023/03/image5-5.png)
Amazon SNS messages can be used as triggers for AWS Lambda functions that perform various operations.
![](https://datascientest.com/wp-content/uploads/2023/03/image1-7.png)
As we’ve just discussed, Amazon SNS and SQS are often used together, one for publishing messages, the other for queuing them.
![](https://datascientest.com/wp-content/uploads/2023/03/image3-5.png)
If an EC2 instance, database or other resource fails, Amazon SNS can be used to alert system administrators via Cloudwatch.
![](https://datascientest.com/wp-content/uploads/2023/03/image6-5.png)
Amazon SNS can publish notifications of events related to the infrastructure (AWS Elastic Beanstalk service, for example).
![](https://datascientest.com/wp-content/uploads/2023/03/image11-1.png)
Your users using your S3 resources can be notified of new events (uploading or modifying information in an S3 bucket, for example).
Conclusion
AWS SNS is a powerful and versatile messaging tool that enables messages to be sent to multiple endpoints (such as email, SMS, SQS queues, mobile applications, etc.). Amazon SNS can also be integrated with other AWS services to create resilient, scalable communication architectures.
Â
đź’ˇRelated articles:
Now that you know everything there is to know about Amazon SNS, you can start learning. To do so, take a look at the DataScientest training course dedicated to Amazon Web Service.