Why is AWS SNS (or Simple Notification Service) so popular among business users? AWS SNS, you can send SMS or text messages to recipients in over 200 countries. Plus, there is no minimum or upfront fee - and like any cloud-based service, you only pay for what you use.
- What is AWS SNS?
- How does AWS SNS work?
- What are the benefits of Amazon SNS?
- How does Amazon SNS message filtering work?
What is AWS SNS?
In simple terms, AWS Simple Notification Service (or AWS SNS) is a cloud-based web service that delivers messages. In other words, AWS SNS service coordinates and manages the delivery of push messages to clients or subscribed endpoints. AWS SNS, you can also create and deliver a messaging service for distributed networks and serverless applications.
Easy to configure on the cloud, AWS SNS is a scalable and cost-effective service that can create and publish from cloud-based applications to other applications. In the following sections, let’s discuss how Amazon SNS works and how to configure its complete setup.
AWS SNS is a push-based messaging service that sends messages from publishers to many subscriber endpoints.
How does push-based messaging work? In this form, a publisher sends out a message to the subscriber immediately instead of storing the message.
Who is a publisher? A publisher is an entity who sends the messages to the message topics that they have created or have the permission to publish.
Who is a subscriber? A subscriber is an entity who receives the messages to the topics that they have subscribed to.
Additionally, SNS service can also send messages to different devices by delivering push notifications to Apple, Google, and Windows-based devices.
Learn more about AWS
How does AWS SNS work?
As mentioned earlier, AWS SNS uses the Publisher-Subscriber model to send messages to its endpoints. Using Amazon SNS, you can filter the messages to a larger number of subscribers or end points through mobile messages, SMS, and email.
- Also known as a producer, publishers create and send the messages to the AWS SNS service.
- Subscribers, on the other hand, receive the published messages from the SNS service over supported network protocols like Amazon SQS, AWS Lambda, or HTTP/ HTTPS.
Shown below is an illustration of the various steps executed by AWS SNS.
Here are the exact workflow steps that are Implemented by AWS SNS:
1) First, the publisher sends out the required notifications that are to be delivered to subscribers.
2) The published messages are delivered to the SNS service, which has the following key components:
- SNS Topic – that is used to filter out the messages that have to be sent to different subscribers. As an AWS developer, you first need to create an SNS topic that acts as the access point for subscribers. Using the topic, subscribers can receive message notifications on their selected subject.
- Message Filter – After being decoupled using topics, the SNS messages enter the message filter, which further filters the messages based on the subscriber’s selected policy. Post the policy checking and permissions, the messages are finally sent to the respective subscribers.
Subscribe to our youtube channel to get new updates..!
3) The subscriber receives the message through subscribing queues or microservices. Subscribers provide useful information such as URL address, email address, or phone number in order to receive the message.
Here are some of the common types of SNS messages that are sent:
Application & System alerts, that are automatic user notifications triggered by predefined thresholds and sent to specific users through SMS or email.
Push email or text messaging, which are two ways of sending messages to individuals or groups (example, news article notifications sent to the newspaper subscribers).
Mobile push notifications, that are direct messages sent to mobile apps (example, notification about any app update that is available for installing).
What are the benefits of Amazon SNS?
Amazon SNS offers 4 key benefits including:
The Amazon SNS service stores its messages in cross availability zones across AWS regions. As a result, each message is now available across multiple regions at the same time – thus providing high reliability. Additionally, Amazon Web Service (AWS) has a global network of data centres that allows publishers to send messages at any time.
Amazon SNS also supports messaging on all AWS endpoints including Amazon SQS and AWS Lambda. In case the subscriber endpoint is not supported, the SNS service retries message delivery and can move its messages to dead-letter queries (or DLQ).
With the Amazon SNS service, you can dynamically scale the number of your message requests from any application. Amazon SNS uses the scaling capability of the AWS cloud platform to achieve this benefit.
Apart from automatic scalability, Amazon SNS is designed for high throughput and changes in traffic patterns. With Amazon SNS, you can plan your workload using capacity planning and provisioning. Plus, there is no upfront cost nor the need to install any messaging software.
Using Amazon SNS service, you can simplify your overall messaging architecture by removing your message filtering mechanism (from the subscriber) and message routing (from the publisher). The SNS service takes care of your message filtering that allows subscribers to only receive messages of their interest – instead of all the published messages in the SNS topic.
As an SNS topic owner, you can set topic-related policies that specify the type of network protocols. You can also specify the users who can publish or subscribe to a particular topic. Other security measures include the limit on the number of daily messages along with keeping messages for “one-time password” (or OTP) transactions private and secure.
Amazon SNS also supports message encryption to keep your data secure. With the use of Amazon PrivateLink service, you can publish private messages to SNS topics from any Amazon VPC subnet.
How does Amazon SNS message filtering work?
Let’s now understand how Amazon SNS uses message filtering to deliver a subset of SNS topic messages to the subscribed endpoints. For simplicity, let’s take a business website that routes user requests to different backend servers.
These server network comprises of:
- 1 server to handle user requests of “type 1.”
- 1 server to handle user requests of “type 2.”
- 1 server for data analytics that handles user requests of both “type 1” and “type 2.”
Here are the 6 steps to implement message filtering with Amazon SNS service:
1) Create an Amazon SNS Topic.
The first step is to create the Amazon SNS topic that will publish messages – whenever any user request is made on the website.
- Open the AWS Management Console and sign-in with your username and password.
- Open the service console for Amazon SNS using the “AWS Services” search box.
- From the landing page of the SNS console, click “Start with an overview” followed by “Topics” from the left side menu.
- Next, click “Create topic” and then type the name of your topic (“Topic_1”) in the “Topic name” box of the dialog box (shown below).
- Click “Create topic” in the above dialog box to create and add the new topic to the “Topic” details page.
2) Create the Amazon SQS Queues
The next step is to create the Amazon SQS queues that will be subscribed to the SNS topic. The website backend servers poll the user requests from its corresponding SQS message queue. For this example:
- Queue_1 handles user requests of “type 1.”
- Queue_2 handles user requests of “type 2.”
- Queue_3 handles user requests of both “type 1” and “type 2.”
- Open the AWS SQS Console and sign-in with your username and password.
- Next, from the “Create New Queue” page, enter “Queue_1” in the “Queue Name” box. With the “Standard Queue” option selected, click “Quick-Create Queue.”
- Repeat the above step b to create two more queues with names “Queue_2” and “Queue_3.” After creating, all these three SQS queues are listed in the SQS console page.
3) Subscribe the Queues to the Topic
This step is necessary to subscribe to the newly created SQS queues to the Amazon SNS topic that will send out relevant SNS messages. For our example, we shall subscribe our three queues (Queue_1, Queue_2, and Queue_3) to “Topic_1” topic.
- From the available list of queues on the AWS SQS console, select the three queues and then click Queue Actions > “Subscribe Queues to SNS Topic.”
- From the “Choose a Topic” list in the “Subs
- cribe to a Topic” dialog box, select your listed SNS topic (Topic_1) that was created by you.
- If you want to subscribe your queues to SQS queues created by an external user, use the “Topic ARN” field.
- Click Subscribe to subscribe the selected queues to the specific topic.
4) Set Filter Policies to the SNS Subscriptions
After creating your SNS topic and SQS queues, you now need to set filter policies to your SNS subscriptions. Created as a JSON doc, a filter policy defines the type of message notifications that would interest the subscriber. Subscriptions without any filter policies would receive all messages that are published to the SNS topic (in our example, Queue_3 as it handles all requests).
- From the Amazon SNS console, click Topics, then select “Topic_1” from the available list of topics.
- From the “Topic_1” details page, you can now view all the SQS queues subscribed to this topic. Here is a sample screen.
- Select each queue, then click Edit to open the “Edit subscription” page where you can edit the filter policy for the queue.
- Use the JSON editor to enter the JSON code (example, “request_type”:[“type 1”] for Queue_1).
- After making the changes, save your changes.
- Repeat the above steps for each of the other two queues. For Queue_3, you don’t need to enter any filter policy as it processes all event messages published to the topic.
5) Publish Messages to the Topic
The next step is to test the message filtering mechanism to see if it publishes the right messages to the subscribers.
a. From the “Topic_1” details page in the Amazon SNS console, click “Publish a message.”
b. Enter the following message details in the “Publish message to topic” page. Here is a sample screen:
- Subject (optional): contains the message subject (for example, “Message#1”).
- Keep the “Identical payload for all delivery protocols” option selected.
- Message body: contains the body of the message to be sent to the endpoint.
- Message attributes: contains the parameters used in the message. For our example, Type as “String,” Name as “request_type,” and Value as “type 1.”
c. Publish your first message.
d. Repeat the above steps to add two more messages (Message#2 and Message#3) with the same parameters as above. For both messages, specify the Value attribute as “type 2.”
6) Verify Your Message Deliveries
The next step is to verify if the new messages are routed to the correct SQS queue with the message filter policy.
- From the Amazon SQS console, select your queue followed by Queue Actions > View/Delete Messages.
- Click on “Start Polling for Messages” to start receiving the messages.
- Repeat the above steps for the remaining queues.
You will observe that Queue_1 will receive only Message#1 – while Queue_2 will receive both Message#2 and Message#3. At the same time, Queue_3 will receive all the three messages as it does not have any configured filter policy.
With the use of the Amazon Simple Notification Service (or SNS), you can deliver the right messages to subscribers or endpoints. Through the use of the publisher-subscriber model, Amazon SNS is a highly available and scalable service for sending push messages to distributed systems, microservices, and serverless applications.
Do you want to know more about the capabilities of the AWS SNS service and how it can work for you? Leave behind your comments in the section provided below.
List Of AWS Courses Offered By Mindmajix:
|AWS Certified SysOps Administrator||AWS Certified Solutions Architect / Professional|
|AWS Certified Developer||AWS Certified DevOps Engineer|
|AWS Technical Essentials||AWS Database Migration Service|
|AWS Lambda 2016||and many more...|
If you interested to learn AWS and build a career in Cloud Computing? Then check out our AWS Certification Training Course at your near Cities
AWS Certification Course in Ahmedabad, AWS Certification Course in Bangalore AWS Certification Course in Chennai, AWS Certification Course in Delhi, AWS Certification Course in Dallas, AWS Certification Course in Hyderabad, AWS Certification Course in London, AWS Certification Course in Mumbai, AWS Certification Course in NewYork, AWS Certification Course in Pune
These courses are incorporated with Live instructor-led training, Industry Use cases, and hands-on live projects. This training program will make you an expert in AWS and help you to achieve your dream job.