What is Amazon Simple Notification Service (SNS)?

  1. Home
  2. AWS
  3. What is Amazon Simple Notification Service (SNS)?
What is Amazon Simple Notification Service (SNS)

Amazon SNS (Amazon Simple Notification Service) is a managed service that delivers messages from publishers to subscribers (also known as producers and consumers). Publishers communicate with subscribers asynchronously by sending messages to a topic, which serves as a logical access point and communication route for subscribers. Clients can subscribe to the SNS topic and receive published messages through any supported endpoint, including Amazon Kinesis Data Firehose, Amazon SQS, AWS Lambda, HTTP, email, mobile push notifications, and mobile text messaging (SMS).

What is Amazon SNS?

The Simple Notification Service (Amazon SNS) is used to send push notifications from an application to subscribing ends or other programs. It’s a fully messaging service for communication between applications (A2A) and people (A2P). It allows you to build a Topic, which serves as a logical access point and communication channel. Each subject has a unique name that specifies the SNS endpoint where publishers can post messages and subscribers can subscribe to receive notifications.

Amazon Simple Notification Service (SNS)

Feature of Amazon Simple Notification Service

  • Automatic Scaling: As the quantity of messages grows, it scales accordingly.
    Message Encryption: It protects your messages from unwanted and unknown access by using encrypted topics. As messages are transmit to subscribing endpoints, they are decrypt.
  • Message Filtering: It allows a subscriber to change a filter policy so that it only receives alerts that are relevant to them.
  • When a message is sent to a topic, it is replicate and push to several endpoints, which is known as message fanout. Asynchronous event alerts are provided by Fanout, allowing for parallel processing.
  • Mobile Notification: It can be trigger by user-initiated actions within an application or by cloud-based business logic. Mobile push alerts for iOS, Android, Fire OS, Windows, and Baidu-based devices are inexpensive to distribute.
  • SNS & Email Messages: Amazon SNS has the ability to send text and email messages (SMTP).

Types of SNS Topics

There are 2 types of SNS Topics:

  • Standard Topic
  • FIFO Topic

How does AWS SNS work?

As previously stated, AWS SNS sends messages to its endpoints using the Publisher-Subscriber paradigm. Through mobile communications, SMS, and email, you can filter messages to a wider number of subscribers or endpoints using Amazon SNS.

  • Publishers, also known as producers, create and send messages to the AWS SNS service.
  • Subscribers, on the other hand, receive the SNS service’s published messages using supported network protocols such as Amazon SQS, AWS Lambda, or HTTP/ HTTPS.

The following are the exact workflow stages that AWS SNS implements:

  • The publisher first sends out the required notices to subscribers.
  • The messages are delivered to the SNS service, which consists of the following components:
    • SNS Topic – This is used to filter out messages that must be distributed to various subscribers. As an AWS developer, you must first establish an SNS topic that will serve as the subscriber’s access point. Subscribers can receive message notifications on their chosen subject by using the topic.
  • The message is delivered to the subscriber via subscribing queues or microservices. In order to get the message, subscribers must submit valuable information such as a URL address, an email address, or a phone number. The following are some of the most prevalent forms of SNS messages:
    • Automatic user notifications triggerby predefined thresholds and sent to particular users through SMS or email are known as application and system alerts.
    • Push email or text messaging are two methods of communicating with people or groups (example, news article notifications sent to the newspaper subscribers).
    • Mobile push notifications are messages sent directly to mobile apps (example, notification about any app update that is available for installing).

How does Amazon SNS message filtering work?

Let’s look at how Amazon SNS employs message filtering to deliver only a subset of SNS topic messages to subscribing endpoints. Take, for example, a company website that sends user queries to many backend servers.

This server network comprises of:

  • Firstly, 1 server to handle user requests of “type 1.”
  • Secondly, 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.”

The following are the six stages to implementing message filtering with Amazon SNS:

Create an Amazon SNS Topic

  • The first step is to set up an Amazon SNS topic that will send out messages whenever a user makes a request on the website.
  • Sign in with your username and password to the AWS Management Console.
  • Using the “AWS Services” search box, find the Amazon SNS service console.
  • Click “Start with an overview” from the SNS console’s landing page, then “Topics” from the left side menu.
  • Then, in the dialogue box, click “Create topic” and type the name of your topic (“Topic 1”) in the “Topic name” field (shown below).
  • To create and add a new topic to the “Topic” details page, click “Create topic” in the above dialogue box.

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.”
  • Sign in to the AWS SQS Console with your username and password.
  • Next, in the “Queue Name” box on the “Create New Queue” page, type “Queue 1.” Click “Quick-Create Queue” with the “Standard Queue” option selected.
    Create two new queues with the names “Queue 2” and “Queue 3” by repeating step b. All three SQS queues are listed in the SQS console page after they are created.

Subscribe the Queues to the Topic

  • This step is required to subscribe to the Amazon SNS topic’s freshly formed SQS queues, which will send out pertinent SNS messages. We’ll subscribe our three queues (Queue 1, Queue 2, and Queue 3) to the “Topic 1” topic as an example.
  • Select the three queues from the AWS SQS console’s available list of queues, then click Queue Actions > “Subscribe Queues to SNS Topic.”
  • Select your listed SNS topic (Topic 1) that you created from the “Choose a Topic” list in the “Subs Describe to a Topic” dialogue box.
  • Use the “Topic ARN” parameter to subscribe your queues to SQS queues created by an external user.
  • To subscribe the selected queues to a certain topic, click Subscribe.

Set Filter Policies to the SNS Subscriptions

You must now apply filter policies to your SNS subscriptions after building your SNS topic and SQS queues. All messages published to the SNS subject (in our example, Queue 3 because it handles all requests) would be received by subscriptions without any filter policies.

  • Click Topics in the Amazon SNS console, then choose “Topic 1” from the list of topics.
  • You can now see all the SQS queues subscribing to this subject from the “Topic 1” information page. Here’s an example of a screen.
  • Select each queue, then click Edit to open the “Edit subscription” page, where you can change the queue’s filter policy.
  • To insert JSON code, use the JSON editor (for example, “request type”:[“type 1”] for Queue 1).
  • Save your changes after you’ve finished making them.
  • For the other two queues, repeat the procedures above. You don’t need to enter any filter policies for Queue 3 because it handles all event messages sent to the subject.

Publish Messages to the Topic

  • The following step is to test the message filtering system to check if it sends the correct messages to the subscribers.
  • In the Amazon SNS console, go to the “Topic 1” details page and click “Publish a message.”
  • On the “Publish message to topic” screen, fill in the following message details. Here’s an example of a screen:
    • Subject (optional): contains the message subject (for example, “Message#1”).
    • Keep the “Identical payload for all delivery protocols” option select.
    • Message attributes: contains the parameters used in the message. For our example, Type as “String,” Name as “request_type,” and Value as “type 1.
  • Publish your first message.
  • Follow the same methods as before to add two more messages (Message#2 and Message#3) with the same parameters. Set the Value attribute to “type 2” for both messages.

Difference between Standard and FIFO Topic

  • A standard topic may send virtually an infinite amount of messages per second, whereas a FIFO topic can send up to 300 messages per second or 10 megabytes per second.
  • A message is delivered at least once in a regular subject, but there may be more than one copy, whereas duplicate messages are not provided in a FIFO topic.
  • Each account can handle 100K standard topics and each subject can support up to 12.5M subscriptions in standard topics, however in FIFO topics, each account can support 1000 FIFO topics and each topic may support up to 100 subscriptions in FIFO topics.

Advantages of Amazon Simple Notification Service

  • Instantaneous Delivery: It works on a push-based system. It is pushed once a message is published on a topic and given to many subscribers.
  • It is inexpensive since it is built on a pay-as-you-go basis, which means we only pay when we utilise the resources and there are no upfront charges.
    Multiple endpoints are supported, making it versatile. Messages can be received by a variety of endpoint types via a variety of transport protocols, including email, SMS, Lambda, Amazon SQS, HTTP, and others.
  • Ease of use: The Web-based AWS Management Console offers the simplicity of a point-and-click interface, making it a very straightforward service to use.
  • Simple Architecture: SNS is used to simplify the messaging architecture by offloading message filtering and routing logic from subscribers and publishers, respectively. Rather of getting all of the messages from the topic, SNS sends only the messages that are of interest to the subscriber.

What are the steps to Configure Amazon SNS?

  • Step 1: 1) Type SNS into the search field and press Enter. Then, on the top left side of the Console, click on Topics, and then on Create Discussion to start a new topic.
  • Step 2: Fill in the title of the topic. Click Create Topic at the bottom of the page.
  • Step 3: The Topic has now been successfully create. Click Create Subscription at the bottom of the page.
  • Step 4: Choose Email as the endpoint and enter the Endpoint address, then click Create Subscription. The subscription will now be create, and the subscription status will be pending.
  • Step 5: The subscriber will receive an email asking them to confirm their membership. To confirm the subscription, the subscriber must open the email and click the Confirm Subscription button. Following that, your subscription will be validated.
  • Step 6: The subscription’s status will now be validate, and you’ll be able to click on the Topic name. Then press the Publish Message button.
  • Step 7: Fill in the subject line and body of the message. Scroll down and select Publish Message from the drop-down menu.
  • Step 8: The message will now be deliver to the subscriber’s email address.

Amazon SNS Pricing

Amazon SNS comes with a generous free tier by default, and it’s also reasonable pricing. There is no need for a subscription; you simply pay for the services you use at the endpoint type you select. Every month, 1 million free mobile push alerts will be sent to us. Following that, each deliver message is charge at $0.5 per million, depending on the recipient’s area.

What is Amazon SNS Security?

  • To safeguard messages from unwanted and unexplained access, SNS offers encrypted topics. The encryption takes place on the server.
    VPC Endpoints are support by Amazon SNS via AWS PrivateLink. We can use VPC Endpoints to send messages to SNS topics from within a VPC without having to go over the public internet.
  • You may restrict which endpoints a topic allows, who is permit to publish to a topic, and under what conditions by using access policies.
  • You may enable AWS X-Ray for messages travelling through Amazon SNS, which makes tracing and analysing messages as they travel to downstream services much easier.

Benefits of SNS

  • Instantaneous delivery: Push-based delivery is the foundation of SNS. This is the most significant distinction between SNS and SQS. When you post a message in a topic and it is distribute to several subscribers, SNS is push.
  • Flexible: Multiple endpoint types are supported by Flexible SNS. Messages can be receive by a variety of endpoint types via a variety of transport protocols, including email, SMS, Lambda, Amazon SQS, HTTP, and others.
  • Inexpensive:
  • SNS service is low since it is built on a pay-as-you-go basis, which means you only pay when you use the resources and there are no upfront expenses.
    User-friendliness.
  • Ease of use: The SNS service is incredibly easy to use, thanks to the web-based AWS Management Console’s point-and-click interface.
  • Architecture that is simple: SNS is used to simplify the messaging architecture by offloading message filtering and routing complexity from subscribers and publishers, respectively.

To Conclude!

Amazon SNS is meant to be used in conjunction with other Amazon Web Services like Amazon SQS and EC2. Applications operating on Amazon EC2 can, for example, publish event/information changes to Amazon SNS and distribute them to all other end-users promptly. Furthermore, the subscriber can choose and select Amazon SQS as a delivery mechanism that sends notifications to various SQS queues in parallel style, ensuring message persistence and formal assurance that the messages are delivered. If you use Amazon SNS, you should enable it on your mobile devices to take advantage of its features.

AWS Certified Solutions Architect Associate free practice test papers
Menu