Quick Tips to use Amazon Simple Notification Service (SNS)

Are you preparing for AWS Certified Developer Associate certification exam? In this space, we are writing series of articles on topics which are covered in the developer associate certification exam. In this article, we are explaining one of the important concept Simple Notification Service (Amazon SNS). You would expect  few questions from this topic for developer associate exam. You can subscribe to us for receiving the further updates on this topic.  

Developer Associate certification exam is the most easiest exam in the associate level, it is good idea to start your certification from this exam. Also we would recommend you to pass the solutions architect certification exam which covers the concepts of all the services offered in AWS.

Developer Associate Syllabus

Here is the snapshot of blueprint for developer associate is covered in the developer associate exam.

aws-developer-associate-blueprint

Amazon SNS

Amazon SNS is a fully managed notification service provided by AWS. Some of the key features of Amazon SNS are

  • It is a cost effective method to push notifications to mobile users, email recipients or even other distributed systems.
  • You can send messages to a variety of platforms such as iOS, Android, Java, Python, PHP, Node.js, or .NET SDKs from AWS.
  • You can also get the delivery status information via Amazon CloudWatch on success rates, failure rates, and dwell times for mobile push messages as well as deliveries to SMS, SQS, HTTP, and Lambda destinations.
  • Use SNS as a message bus to send messages, alarms, and notifications from your AWS services such as Amazon RDS, CloudWatch, and S3 to other AWS services such as SQS and Lambda
  • A Message in SNS has a format which has the following parts attached to it. Please note that for the AWS Developer exam , this is important to note.
    • MessageId: A Universally Unique Identifier, unique for each notification published.
    • Timestamp: The time (in GMT) at which the notification was published.
    • TopicArn: The topic to which this message was published
    • Type: The type of the delivery message, set to “Notification” for notification deliveries.
    • UnsubscribeURL: A link to unsubscribe the end-point from this topic, and prevent receiving any further notifications.
    • Message: The payload (body) of the message, as received from the publisher.
    • Subject: The Subject field – if one was included as an optional parameter to the publish API call along with the message.
    • Signature: Base64-encoded “SHA1withRSA” signature of the Message, MessageId, Subject (if present), Type, Timestamp, and Topic values.
    • SignatureVersion: Version of the Amazon SNS signature used.

One of the key aspects for the Developer exam is to know how to setup SNS and use the SNS service. So let’s look at how we can use SNS in more detail.

Working with SNS

  • Log into your AWS Console. You will see Simple Notification Service under the Messaging option.

aws-sns-messaging-option

  • The first order of business is to create a topic. A topic is like a channel where messages get published to. Then you have systems which act as subscribers which will pull messages from the SNS topic. For click on Create topic.

 

aws-sns-create-topic

  • Provide a name and Display Name for the topic

aws-sns-create-new-topic

And then click on Create Topic.

  • Next we need to create a subscription. There are the places where the SNS messages will be published to.

AWS SNS -Create Topic

Click on the topic and then choose the menu option Action->Subscribe to topic

You have the following protocols for creating a subscription

  • “HTTP”, “HTTPS” – Subscribers specify a URL as part of the subscription registration; notifications will be delivered through an HTTP POST to the specified URL.
  • ”Email”, “Email-JSON” – Messages are sent to registered addresses as email. Email-JSON sends notifications as a JSON object, while Email sends text-based email.
  • “SQS” – Users can specify an SQS standard queue as the endpoint; Amazon SNS will enqueue a notification message to the specified queue (which subscribers can then process using SQS APIs such as ReceiveMessage, DeleteMessage, etc.). Note that FIFO queues are not currently supported.
  • “SMS” – Messages are sent to registered phone numbers as SMS text messages.

AWS SNS- Create Suscription

For the subscription we will choose the email option and you can provide any valid email option.

AWS SNS- Create Subcription Email Option

Next click on Create subscription.

  • Now if you go to the gmail account you will see that you have got an email notification from SNS to confirm the subscription.

AWS SNS- Subcription Email Notification

You can go ahead and confirm on the subscription.

You will then see a confirmation to the subscription.

AWS SNS- Subcription Confirmation

And now if you go to SNS and see the subscriptions, you will see the successful subscription.

AWS SNS- Subcription successful

  • Now let’s publish a message to the topic. In the topics section, click on the Topic and select Publish to topic.

AWS SNS- Publish Message to Topic

Enter a subject and message. Then click on the Publish message button.

AWS SNS - Enter Message

You will then get a notification that the message has been published.

AWS SNS - Message Published

 

  • If you now go back to the gmail account , you will see that the message has come to the account via SNS.

AWS SNS - Message in Gmail

So we have seen how we can configure a topic and send messages to this topic. This topic will then be delivered to multiple subscribers, basically any of the available protocols which subscribe to the service.

Adding another Subscriber

Now let’s see how we can add another subscriber to the SNS topic. Now we will add a subscriber as SQS.

Let’s assume we have an SQS queue with the following arn

arn:aws:sqs:ap-southeast-1:085363624145:Demo

  • Let’s go to our topic and click on Subscribe to topic

AWS SNS - Subscribe to Topic

  • Now in the next screen lets choose the option of SQS and add our queue url. Click on the Create subscription.

AWS SNS - Create Subscription to Topic

Now when you go to subscriptions you will see the added subscription

AWS SNS - Added Subscription

 

  • Now let’s send a test message to the topic. Let’s give the subject and the message as ‘New Test Message’

AWS SNS - Test Message to Topic

Now if you go to your SQS queue, you will see the Test Message and you will also see the Test Message in your gmail account.

 

Final Points to Remember about SNS

  • It is a cost effective method to push notifications to mobile users, email recipients or even other distributed systems.
  • You can send messages to a variety of platforms such as iOS, Android, Java, Python, PHP, Node.js, or .NET SDKs from AWS.
  • The first part is to create a topic in SNS. This will be used to publish all your messages to SNS.
  • Each topic will then have subscribers which can be used to get the messages. The following protocols are available for SNS subscribers
    • “HTTP”, “HTTPS”
    • ”Email”, “Email-JSON”
    • “SQS”
    • “SMS” – Messages are sent to registered phone numbers as SMS text messages.
  • You can have multiple subscribers for each topic.
  • A Message in SNS has the following parameters
    • MessageId
    • Timestamp
    • TopicArn
    • Type
    • UnsubscribeURL
    • Message
    • Subject
    • Signature
    • SignatureVersion

Summary

In this article we have explained about how to use Simple Notification Service (Amazon SNS). This is one of the most important service offered by Amazon Web Services (AWS). You would expect few questions from this topic in your certification exam. 

If you are preparing for the AWS certifications exam and looking for any help, please send us a mail to call to our customer support team. 

About Pavan Gumaste

Pavan Rao is a programmer / Developer by Profession and Cloud Computing Professional by choice with in-depth knowledge in AWS, Azure, Google Cloud Platform. He helps the organisation figure out what to build, ensure successful delivery, and incorporate user learning to improve the strategy and product further.

1 thought on “Quick Tips to use Amazon Simple Notification Service (SNS)”

  1. Hi, I was looking information about SNS and I found this article. I have been using SNS for several months I didn’t find how to resolve this issue.
    When I create the topic and subscribe a user, the user receive the email the same way as your post says, and the same kind of email. So the question is very simple, would you know how to edit the email template?? I don’t want my users to receive an email with the topic information and the account information, what I want is my users to receive a branded email with the information of the service they are suscribing.

Leave a Comment

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

Scroll to Top