100 Days of DevOps — Day 2 -Introduction to Simple Notification Service(SNS)

What is SNS?

AWS SNS is a web service that coordinates and manages the delivery or sending of messages to subscribing endpoints or clients.

Step 1: Create a topic

Step2: Subscribe to a Topic

Step3: Publish to the topic

$ aws sns create-topic --name "my-demo-sns-topic"{"TopicArn": "arn:aws:sns:us-west-2:1234556667:my-demo-sns-topic"}
$ aws sns subscribe --topic-arn arn:aws:sns:us-west-2:123456667:my-demo-sns-topic --protocol email --notification-endpoint test@gmail.com{"SubscriptionArn": "pending confirmation"}
$ aws sns publish --topic-arn arn:aws:sns:us-west-2:1234567:my-demo-sns-topic --message "hello from sns"{"MessageId": "d651b7d5-2d66-58c8-abe4-e30822a3aa3e"}
$ aws sns list-subscriptions{"Subscriptions": [{"Owner": "1234567889","Endpoint": "test@gmail.com","Protocol": "email","TopicArn": "arn:aws:sns:us-west-2:1234567788:HighCPUUtilization","SubscriptionArn": "arn:aws:sns:us-west-2:1234567788:HighCPUUtilization:a28e2be8-40cd-4f8b-83d9-33b2c858749d"},
aws sns unsubscribe --subscription-arn arn:aws:sns:us-west-2:1234567899:my-demo-sns-topic:f28124be-850b-4a2e-8d3e-a3dc4f7cca1a
$ aws sns delete-topic --topic-arn arn:aws:sns:us-west-2:1234567788:my-demo-sns-topic
$ aws sns list-topics{"Topics": [{"TopicArn": "arn:aws:sns:us-west-2:123333345555:mydemosnstopic"}]}
# main.tfresource "aws_sns_topic" "alarm" {
name = "alarms-topic"

delivery_policy = <<EOF
"http": {
"defaultHealthyRetryPolicy": {
"minDelayTarget": 20,
"maxDelayTarget": 20,
"numRetries": 3,
"numMaxDelayRetries": 0,
"numNoDelayRetries": 0,
"numMinDelayRetries": 0,
"backoffFunction": "linear"
"disableSubscriptionOverrides": false,
"defaultThrottlePolicy": {
"maxReceivesPerSecond": 1

provisioner "local-exec" {
command = "aws sns subscribe --topic-arn ${self.arn} --protocol email --notification-endpoint ${var.alarms_email}"
# variables.tfvariable "alarms_email" {
default = "laprashant@gmail.com"
# outputs.tfoutput "sns_topic" {
value = "${aws_sns_topic.alarm.arn}"



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prashant Lakhera

Prashant Lakhera

AWS Community Builder, Ex-Redhat, Author, Blogger, YouTuber, RHCA, RHCDS, RHCE, Docker Certified,4XAWS, CCNA, MCP, Certified Jenkins, Terraform Certified, 1XGCP