Amazon Web services offer many services out of which Simple Notification Service (SNS) was launched in 2010. As the name suggests its primary job is to notify. It provides a low-cost infrastructure for the mass delivery of messages, predominantly to mobile users. In case you are someone new to AWS, take a look at my article to understand what is AWS and what solution they offer.
- What is SNS?
- How does it work?
- How did I use SNS?
What is SNS?
According to the documentation, “Amazon Simple Notification Service (Amazon SNS) is a fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication.”
How does it work?
Amazon SNS follows a pub/sub functionality, which means we need to subscribe to a topic in order to publish. There are two important terminologies you need to be aware of, in order to use this service. They are Topics and Subscriptions. There are two types of topics, FIFO (first-in, first-out) and Standard. In FIFO, the message is exactly delivered only once with strict message ordering. Only SQS can be subscribed to using this topic. A Standard topic assures message delivery at least once with best effort message ordering. It can be subscribed with various protocols like SMS, email, HTTP/HTTPS, and also other services like AWS SQS, Lambda, Kinesis Data Firehouse, etc
Here you can understand that SNS is a push-based service allowing publisher systems to fan-out messages to a large number of subscriber systems. The A2P functionality enables you to send messages to users at scale via SMS, mobile push, and email. Look into the official documentation to know more features.
- Decouple your application into smaller, independent components that are easier to develop, deploy and maintain.
- Send messages directly to millions of users
- Automatically scale your workload
- Simplify your architecture with Message Filtering
How did I use SNS?
I personally got exposed to SNS when I had a requirement to send an email. Only then I realized it’s actually more than an email notifier. Since it is easy to set up and event-driven I highly rely on it. I mostly use SNS with a combination of SQS and Lambda. By using SQS in the middle I make sure the message is not lost. After all, the cost of using SNS is very low. Take a look at the official documentation to know more about pricing.
Note: SNS is not an ideal solution for sending email since the user has to approve whether they want to receive a message from this topic. In this case, you can use another AWS service called Amazon Simple Email Service (SES).
In the following demo, let’s see how to subscribe a topic to email protocol.
- Open the Simple Notification Service console using the search bar.
- Click on the three lines that are highlighted and select topics.
- Select standard type and enter the topic name. Then click Create topic.
- Your topic has been successfully created. Now click create subscription.
- Select the protocol type as email and enter your email id in the endpoint. Then click create subscription.
- Now open your email. You will receive an email as shown below.
- Click “confirm subscription”. And now it’s time to see things in action.
- Go to the topic you created and click on Publish message. Now scroll down and type your message under the Message body to send to the endpoint as shown below and click Publish message.
- Now go to the email id you subscribed to. You can find an email as shown below.
This article is just an overview of SNS. Once you get used to the console and API’s it is just like a cup of tea. Happy programming!!