What is AWS SNS?

What is AWS SNS?

Hello, Bits Lovers!, and welcome back. This article will learn about another service that will help us decouple our application on AWS. We deliver push-based messaging utilizing the AWS Simple Notification Service or, as it’s more typically known, SNS.  

If you are planning to discover and learn the differences between AWS SNS vs SQS, you can take advantage of this post.

Now, you may be thinking: What is push-based messaging? And, how does this approximate to that previous article that we learned about, poll-based? Later, we will examine SNS and why we would like to use it. Afterward, we will list all the crucial settings we must know to configure it properly. Also, we will have one step-by-step on how to create an SNS Topic and how to test it. And finally, we will have some exam tips.  

So, let’s go forward and have some fun!

What is push-based messaging?

Now, the main question is: what is push-based messaging? 

If you remember from our previous article, poll-based messaging is where the mailman pleasingly brings our letter and delivers it to our mailbox, and we get to reach the mailbox anytime we’re willing to get our mail. Push-based messaging is identical but also significantly different. Rather than the mailman pleasingly delivering that message to our mailbox, the mailman brings the message, goes to our home, kicks open our door, sprints into our room, and gives us the letter. We have to be prepared for that mailman to show up with that message, so rather than choosing when we like to go and get that message. Well, where does this match the AWS architecture? I think that you know the answer. The SNS does a lot for us.  

What is AWS SNS?

SNS is a push-based messaging product from AWS that sends messages to the endpoints subscribed to it. We can use it to alert a system or an individual.

And we don’t need to worry about if we need to scale horizontally or vertically our service to deliver the messages in high demand. AWS already takes care of it for us.

So, SNS can deliver details on our behalf. As we saw, we don’t have to wait for the end-users to get that content, like SQS. Currently, this can be helpful in a couple of different circumstances. First, we want to go ahead and ship out an email anytime when one event happens. For example, when a CloudWatch alarm goes off, we can send an email or send an SMS message. We ship, for example, “Hey, A event occurred, and B people or service need to be aware of it.” So, the keyword that we like to associate with SNS is the push-based message.  

What is push-based messaging
What is push-based messaging?

SNS Settings

Which settings do we need to be careful for push-based messaging? Well, to me, it is a tiny easier than that poll-based because, as the message arrives in, it instantly goes out, so we don’t have to be concerned regarding something like visibility timeouts or message locking or anything related. But there is still some configuration that we have to look at.

Subscribed to an SNS topic

What mean to subscribe to an SNS topic?

The general process is we create an SNS topic, and from there, we determine what will receive data from that topic. In other words, when a message is pushed to that topic, who, where, or what does it go to? Well, we have a mixture of further options here. For example, it could be the Kinesis Data Firehose or a Lambda Function. We have email, SMS, HTTPS, HTTP, and SQS.  

But you might be assuming, “Why would we want to connect the SNS and SQS?” We can do a fan-out, where one message is delivered to SNS. Then it is copied and sent to multiple SQS queues because, maybe, we have different groups of backend servers that all retrieve from different queues that need to be warned that that message has come in and they have to process it.  

SNS Message Size Limit

The message size is the same as we learned from our SQS article: 256 kilobytes of text in any format.  

Dead-Letter Queue Support

We have support for that dead-letter queue. As we saw in our previous article, dead-letter queues are not particular queues. So, it is not another SNS topic. This is an SQS queue that is subscribed to SNS because SNS will not retry those deliveries if one should fail, except HTTP. Everything else, we would sideline into this queue and then deal with it later.  

FIFO or standard SNS

We also have support for FIFO or standard SNS. And FIFO isn’t particularly as helpful as we might consider in this situation because the only service that can be subscribed to a FIFO SNS topic is SQS queues. This is just for when we’re accomplishing that fan-out into multiple SQS queues. Otherwise, 99.9% of the time, we’re just utilizing a standard SNS topic.  

SNS Encryption

We have encryption, just like SQS. It’s also encrypted in transit by default, but we can add that SNS encryption at rest by merely checking a checkbox and choosing a KMS key. Really simple.

SNS Access Policy

We have an identical access policy that we can use for our S3 buckets, SQS queues, or SNS. Also, we can manage who or what can post data into these SNS topics.  

One bonus tip: while this is an essential service, it will not show up heavily on the exam. Because there’s not particularly as much that we have to squeeze and configure, when we’re on the exam, we can typically just associate AWS SNS with any alert service or push-based message that needs to be shipped out. So it’ll be there, but SQS is one that we desire to dive deep into. 

So, let’s go ahead and jump into the console, and we’ll send out that email and fan out some messages into some SQS queues.  

SNS Topic

How to create SNS topic in aws

  1. Go to Amazon SNS console.
  2. In the left menu pane, select Topics.
  3. Now, on the Topics page, select Create topic.
  4. The default option is the FIFO topic. Select Standard.
  5. Enter a Name for the topic in the Details area, like BisLoversTopic.
  6. On the bottom, click on Create topic.

To see this in action, we need to subscribe to our topic.

How to subscribe to AWS SNS

Create a subscription to the topic

  1. In the menu pane, select Subscriptions.
  2. On the Subscriptions area, select Create subscription.
  3. On the Create subscription area, select the Topic ARN field to display an inventory of all topics that exist in your account.
  4. Please select the topic that we created in the last step.
  5. On the Protocol field, select email.
  6. On the Endpoint field, type an email address to receive the SNS notifications.
  7. Click on Create subscription.
  8. Later, we will see the subscription’s Details.
  9. Please open the email we choose and click on the link to confirm the subscription
  10. After clicking on the link, your web browser will be opened and shows a subscription verification ID.

Now, we are ready to send notifications using SNS. We can do this using SDK, AWS Command Line Tool, or the Console. Let’s see how we can dispatch using AWS Console:

Publish a message on the topic

  1. On the SNS menu, select Topics.
  2. On the Topics area, please select the topic we created before and then select Publish message.
  3. In the Message details area, type a Subject, “Hello Bits Lovers!”. But this step is optional.
  4. In the Message body area, select Identical payload for all delivery protocols, and then type a message body, such as: “Message from an SNS Topic.”
  5. Click on Publish message.
  6. The message is sent to the topic.
  7. Check the email inbox and confirm that you received an email with the published message.

SNS Price

The SNS price is pretty simple. There are no upfront fees, required minimum obligations, or long-term agreements. Instead, we pay just for what we use, founded on the type of topic utilized. As we saw before, SNS topics are Standard or FIFO topics. Also, the price may be different between regions. Also, how we deliver the message will affect the price that we pay, like Mobile Push Notifications, Email/Email-JSON, HTTP, SQS, AWS Lambda, and Amazon Kinesis Data Firehose.

For example, we can pay $0.50 per 1 million AWS SNS requests, $0.06 per 100K notification deliveries using HTTP, and $2.00 per 100K email message deliveries. Also, if we are using SMS messaging, we can dispatch 100 free notification deliveries, and for subsequent notifications, costs vary by destination country.

Exam Tip

The main tip: Anytime you end up with a scenario talking about an alert or notification on the exam, consider SNS. We can utilize it to alert a combination of various endpoints, for example, email, SMS, and text messages. So, words like “push” and “alert” consider the SNS. So recall, anytime we notice that a user must know that an alarm or an event occurred, SNS is your best answer.  

What is push-based messaging? What is AWS SNS? It would be best if you automatically answered those questions in your mind.

Also, an easy word connection: push-based notifications = SNS. That’s what we desire to use.  

CloudWatch and SNS are the best combinations. We know that CloudWatch is the best combination with a bunch of other AWS services, but when we are talking about delivering the CloudWatch notification, that CloudWatch alarm will use SNS.  

Who can subscribe?

We need to understand all possible subscribers that SNS can push messages into, for example, text messages, email, HTTP, SQS, and Kinesis. Then, understand the use cases behind all of them.  

Be careful

The AWS will test and trick you into choosing SES. The means Simple Email Service. But, the SES is based on marketing emails, so for example, if one company requires to spread out email lists to the customers, SES would be a more suitable fit. So, on the exam, they will try and trick you into choosing SES rather than utilizing SNS to ship out email notifications, for instance, from that CloudWatch alarm.  

So, generally, consider SNS 99.9% of the time if you notice an email notification. The SES is just a way to trick.  

No retry for SNS

There is no retry for anything except for HTTP and HTTPS. Everything else, we would sideline into that AWS SQS dead-letter queue, and only if we don’t desire to lose that message. But then, those endpoints have to be up and running to be ready to accept that message.  

SNS Benefits

AWS SNS delivers several benefits driving it a versatile choice for building and integrating loosely coupled, distributed systems:

  • Easygoing message delivery over numerous transport protocols
  • Quick, push-based delivery (it means no polling)
  • Straightforward APIs and effortless integration with your applications
  • Affordable, pay-as-you-go standard with no up-front fees

Conclusion

What is push-based messaging? What is AWS SNS? I hope we resolved that question and you have an excellent base to use SNS. The SNS also belongs to an essential service that helps us achieve high availability on AWS, where fundamental concepts are crucial in your Cloud journey.

Leave a Comment

Your email address will not be published. Required fields are marked *

Free PDF with a useful Mind Map that illustrates everything you should know about AWS VPC in a single view.