Setting Up An Amazon SNS Topic With A Subscriber
What Is SNS?
SNS (Simple Notification Service) is a fully managed pub / sub messaging service for microservices and serverless applications which coordinates and manages the delivery or sending of messages to the endpoints or subscribers or the client.
What Is SNS Topic?
Topic is a medium which acts as a communication channel which consists of collection of subscribers subscribed to it.
Subscribers can be a HTTP Endpoints , Email , SMS , SQS , Lambda.
This article walks you through the process of creating a SNS Topics and to add a subscriber to it.
Creating SNS Topic:
To create a SNS topic , Login to SNS Console
You should see the following page.

Click Start with an overview,
You will see the Dashboard, In the left pane click Topics ,
Click Create topic

Give a name for the topic ,

You can find multiple options which are optional, Such as
ENCRYPTION:
By default , SNS delivers the messages in the encrypted way, If you want to enable server side encryption which means encrypting the topic at rest.

ACCESS POLICY
Access policy restricts the access to the policy , It defines who can access the topic.
By default , The owner (account_id) of the topic can subscribe and publish to the topic.


You can explicitly define who can publish or subscribe to the topic, Also you can write a custom policy by Clicking the Advanced tab.
DELIVERY RETRY POLICY
This policy defines how many times the SNS should retry publishing to HTTP & HTTPS endpoints.
You can use default retry delivery policy which is 3 retries Or else you can customize it as per your requirement.

DELIVERY STATUS LOGGING
If you want to debug SNS in case of delivery failure or any delivery status. You can enable logging to Cloudwatch logs.
Also You can enable logging for Lambda , SQS , HTTP/S endpoints and application endpoints.
This requires an IAM role , Choose Create new service role.

TAGS
Finally , You can add a tag to the SNS topic to segregate the topics based on the environments.

Click Create topic.
Now that we have successfully created SNS topic.You can find the topic ARN using which you can communicate with other services.

Lets go ahead and create a subscriber for this topic.
Creating Subscription:
To create a subscription , Click create subscription,

You will be asked to choose the protocol such as lambda , SMS , email , SQS , http/s endpoints.
For this tutorial , I will choose Email.
Provide the email id and click create subscription.
But whenever we add a subscriber to the SNS topic we should confirm it.
Else It will be pending for confirmation and subscriber wont get the messages published by the SNS topic.
Go to your email , You should have got a mail from Amazon SNS like this,

Click Confirm subscription , And your subscriber will be confirmed.

Now go back to SNS console and refresh the page , You should see the subscription is confirmed.

Now that we have a SNS topic and a confirmed subscriber.
Now Lets test the pub/sub messaging system , By publishing a mesage to the SNS topic and the subscriber (email) should receive the message.
Publishing Message To Subscriber:
To do this , Go to the Topic and click Publish Message ,

In the publish message page , You can provide a Subject for your Message ,

Under Message body , Enter the message you want to send to the subscribers.

Then click Publish Message.
As I have checked my Mail box , I have received a message from SNS topic.

Hope you like it , Thanks for reading this article.
Please do check out my other articles.