Amazon SNS

Amazon SNS -Simple Notification Service | AWS Tutorials

Amazon SNS (Simple Notification Service) is a highly available, durable, secure, fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications. Amazon SNS provides topics for high-throughput, push-based, many-to-many messaging. Using Amazon SNS topics, your publisher systems can fan out messages to a large number of subscriber endpoints for parallel processing, including Amazon SQS queues, AWS Lambda functions, and HTTP/S webhooks. Additionally, SNS can be used to fan out notifications to end users using mobile push, SMS, and email. 

A web service that makes it easy to set up, operate, and send notifications from the cloud. SNS follows  the “publish-subscribe” (pub-sub) messaging paradigm, with notifications being delivered to clients using a “push” mechanism rather than to periodically check or “poll” for new information and updates.  

Amazon SNS stands for Simple Notification Service. 

  • It is a web service which makes it easy to set up, operate, and send a notification from the cloud. 
  • It provides developers with the highly scalable, cost-effective, and flexible capability to publish messages from an application and sends them to other applications. 
  • It is a way of sending messages. When you are using AutoScaling, it triggers an SNS service which will email you that “your EC2 instance is growing”. 
  • SNS can also send the messages to devices by sending push notifications to Apple, Google, Fire OS, and Windows devices, as well as Android devices in China with Baidu Cloud Push. 
  • Besides sending the push notifications to the mobile devices, Amazon SNS sends the notifications through SMS or email to an Amazon Simple Queue Service (SQS), or to an HTTP endpoint. 
  • SNS notifications can also trigger the Lambda function. When a message is published to an SNS topic that has a Lambda function associated with it, Lambda function is invoked with the payload of the message. Therefore, we can say that the Lambda function is invoked with a message payload as an input parameter and manipulate the information in the message and then sends the message to other SNS topics or other AWS services. 
  • Amazon SNS allows you to group multiple recipients using topics where the topic is a logical access point that sends the identical copies of the same message to the subscribe recipients. 
  • Amazon SNS supports multiple endpoint types. For example, you can group together IOS, Android and SMS recipients. Once you publish the message to the topic, SNS delivers the formatted copies of your message to the subscribers. 
  • To prevent the loss of data, all messages published to SNS are stored redundantly across multiple availability zones. 

Components Amazon SNS: 

SNS Publishers and Subscribers: 

Amazon SNS is a web service that manages sending messages to the subscribing endpoint. There are two clients of SNS: 


Publishers are also known as producers that produce and send the message to the SNS which is a logical access point. 


Subscribers such as web servers, email addresses, Amazon SQS queues, AWS Lambda functions receive the message or notification from the SNS over one of the supported protocols (Amazon SQS, email, Lambda, HTTP, SMS). 

 SNS Topics: 

  • Instead of including a specific destination address in each message, a publisher sends a message to a topic. SNS matches the topic to a list of subscribers who have subscribed to that topic, and deliversthe  messageto each of those subscribers.  
  • Each topic has a unique name that identifies the SNS endpoint for publishers to post messages and subscribers to register for notifications. 
  • A topic can support subscriptions and notification deliveries over multiple transports. 

 SNS also logs the the delivery status of notification messages sent to topics with the following SNS endpoints:  

  • Application
  • HTTP
  • Lambda 
  • SQS

Message Attributes: 

  • Amazon SNS supports delivery of message attributes. Message attributes allow you to provide structured metadata items (such as time stamps, geospatial data, signatures, and identifiers) about the message.  Message attributes are optional and separate from, but sent along with, the message body. 
  • You can use message attributes to help structure the push notification message for mobile endpoints.  The attributes are not delivered to the mobile endpoint, as they are when sending messageswith  messageattributes to SQS endpoints.  
  • You can also use message attributes to make your messages filterable with subscription filter policies. You apply filter policies to topic subscriptions. 
  • Message attributes contain a name, type, and value that must not be empty or null. The message body should not be empty or null also.

 Message Filtering: 

A filter policy is a simpleJSON object.  

By default, a subscriber of an SNS topic receives every message published to the topic. The filter policy contains attributes that define which messages the subscriber receives.  

 Raw Message Delivery: 

By default, messages are delivered encoded in JSON that provides metadata about the message and topic.  

  • You can send large payload messages using AWS SDK that supports AWS Signature Version 4 signing. 
  • You can also enable raw message delivery for messages delivered to either SQS endpoints or HTTP/S endpoints.

 System to System Messaging: 

  • When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda function is invoked with the payload of the published message. The Lambda function receives the  message payload as an input parameter and can manipulate the information in the message, publish  the message to other SNS topics, or send the message to other AWS services.  
  • When you subscribe a SQS queue to a SNS topic, you can publish a message to the topic and SNS sends  a SQS message to the subscribed queue. The SQS message contains the subject and message that were  published to the topic along with metadata about the message in a JSON document.  
  • When you subscribe an HTTP/s endpoint to a topic, you can publish a notification to the topic and SNS  sends an HTTP POST request delivering the contents of the notification to the subscribed endpoint. When you subscribe the endpoint, you select whether SNS uses HTTP or HTTPS to send the POST  request to the endpoint. 

 User Notification: 

  • You have the ability to send push notification messages directly to apps on mobile devices. Push notification messages sent to a mobile endpoint can appear in the mobile app as message alerts, badge updates, or even sound alerts.  
  • Direct addressing allows you to deliver notifications directly to a single endpoint, rather than sending identical messages to all subscribers of a topic. This is useful if you want to deliver precisely targeted  messages to each recipient.  
  • You can use SNS to send text messages, or SMS messages, to SMS-enabled devices. You can send a message directly to a phone number, or you can send a message to multiple phone numbers at once by subscribing those phone numbers to a topic and sending your message to the topic. 
  • You can use the Delivery Status feature to get information on the final disposition of your SMS message.  
  • SMS messages that are of high priority to your business should be marked as Transactional. This ensures that messages such as those that contain one-time passwords or PINs get delivered over routes with the highest delivery reliability. 
  • SMS messages that carry marketing messaging should be marked Promotional. Amazon SNS ensures that such messages are sent over routes that have a reasonable delivery reliability but are substantially  cheaper than the most reliable routes. 

SNS Delivery Retries: 

All messages sent to SNS are processed and delivered immediately. If a message cannot be successfully delivered on the first attempt, SNS implements a 4-phase retry policy:  

1) retries with no delay in between attempts  

2) retries with some minimum delay between attempts  

3) retries with some back-off model (linear or exponential)  

4) retries with some maximum delay between attempts 


  • Monitoring SNS topics using CloudWatch 
  • Logging SNS API calls using CloudTrail 


  • SNS provides encrypted topics to protect your messages from unauthorized and anonymous access. The encryption takes place on the server side. 
  • SNS supports VPC Endpoints via AWSPrivateLink. You can use VPC Endpoints to privately publish messages to SNS topics, from a VPC, without traversing the public internet. 
  • Using access control policies, you have detailed control over which endpoints a topic allows, whois able topublish to a topic, and under what conditions.  
  • You can enable AWS X-Ray for your messages passing through Amazon SNS, making it easier to trace and analyze messages as they travel through to the downstream services.


  • You pay based on the number of notifications you publish, the number of notifications you deliver, and any additional API calls for managing topics and subscriptions. Delivery pricing varies by endpoint type. 


By default, SNS offers 10 million subscriptions per topic, and 1 00,000 topics per account.  

  • A single SMS message can contain a maximum of 140 bytes of information. 
  • With the exception of SMS messages, SNS messages can contain up to 256 KB of text data. 

How does Amazon SNS work? 

The way SNS works resembles mailing groups that you subscribe to in order to receive the content of interest to you. First of all, developers managing an account create a certain topic and publish it via the SNS dashboard. There can be a number of topics as it usually doesn’t make sense to send all the content to all the accounts within an organization. As a matter of fact, Amazon set the limit at 100,000 topics for a single AWS account. 

A topic is an access point that users can subscribe to with a URL, a phone number or an email address to receive its respective notifications. When a new notification is published, it’s filtered to meet subscribers’ policies and, if successful, is delivered to the provided endpoint. 

It’s important to note that, unlike SQS, SNS doesn’t guarantee delivery and won’t retry if sending is unsuccessful for whatever reason. If that happens, a message will be discarded. 

What is Amazon SNS used for? 

Simple Notification Service is frequently used to send system notifications to subscribers of a given topic. These can include alerts received when a server is down, when a new user registers, or when a recurring check is performed. Since different people are interested in different topics, usually dozens of them are created so as not to unnecessarily email or text an entire company. 

Another popular use is with a common “fan-out” scenario that involves the use of Amazon SQS.  

Simple Queue Service is also used to distribute notifications to its users, or, to be precise, to their queues. The messages are not pushed to users, as was the case with SNS, but, instead, they need to “poll” a queue to obtain them. When they do, a message is no longer available for the rest of a network. Such communication guarantees a delivery because it’s asynchronous. Each message will patiently wait in a queue for its addressee to fetch it. This approach to delivering notifications raises an opportunity for an interesting integration with SNS, which bears the aforementioned “fan-out” name. 

Happy Learning !!

Related Posts:

Amazon Web Service – AWS Tutorial

Top 13 Reasons to Why Learn AWS in 2022

What is AWS IAM?

What is Amazon EC2? – Amazon Elastic Compute Cloud

300 AWS Interview Questions and Answers [2023]