Amazon SNS 

Introduction to Amazon SNS 

Amazon Simple Notification Service (Amazon SNS) is a fully managed messaging service designed for high throughput, flexibility, and ease of use. It enables the delivery of messages to many subscribers or services, ensuring that your applications can communicate efficiently across multiple systems and services. 

Amazon SNS – Key Features 

Pub/Sub Messaging: 

SNS supports the publish/subscribe messaging model. A message or notification is sent by a publisher to a topic, which is essentially a logical access point and communication channel. Subscribers to the topic can receive the message via different protocols. 

Multiple Protocols for Message Delivery: 

SNS supports various protocols for delivering messages, including: 

  • HTTP/HTTPS: Deliver notifications over HTTP/HTTPS endpoints. 
  • Email/Email-JSON: Deliver plain text or JSON-formatted messages via email. 
  • SMS: Send messages to mobile devices as text messages. 
  • Amazon SQS: Deliver messages to Amazon Simple Queue Service (SQS) for further processing. 
  • AWS Lambda: Invoke AWS Lambda functions with the message payload. 
  • Application: Send push notifications to mobile devices using services like APNS (Apple Push Notification Service) or FCM (Firebase Cloud Messaging). 

Fanout Architecture: 

SNS enables fanout, where a single message published to an SNS topic is replicated and pushed to multiple endpoints, like SQS queues, Lambda functions, or other destinations, in parallel. 

Message Filtering: 

Subscribers can use filters to specify which messages they want to receive based on message attributes. This allows for more efficient processing by reducing the amount of unwanted data. 

Message Durability and Redelivery: 

Messages are stored across multiple availability zones, ensuring high durability. SNS retries message delivery for a configurable period if the initial delivery attempt fails. 

Event-Driven Architectures: 

SNS is commonly used in event-driven architectures to trigger actions across different services when specific events occur. For example, an SNS topic might trigger a Lambda function when an object is uploaded to S3. 

Security: 

SNS integrates with AWS Identity and Access Management (IAM) to control access to topics and to secure message transmission using encryption. 

Scalability 

SNS is designed to scale automatically to handle a high number of messages and subscribers, making it ideal for use cases where millions of messages need to be distributed globally. 

Amazon SNS – Pricing 

With Amazon SNS, no upfront fees, minimum commitments, or long-term contracts are required. You only pay for what you use, based on the type of topic: Standard or FIFO. Charges are applied at the end of each month based on your usage. 

Standard Topics: Pricing for standard topics is based on the number of API requests made each month and the number of deliveries to different endpoints, with delivery costs varying by endpoint type.  

  • Standard topic requests include publishing, batch publishing, topic owner operations, and subscription owner operations. 
  • The first 1 million requests each month are free; beyond that, the cost is $0.50 per million requests. 

Note: Each 64KB chunk of published data counts as one request. For example, publishing a 256KB payload will be billed as four requests. 

FIFO Topics: FIFO topic pricing is determined by the number of published messages, the number of subscribed messages, and their respective payload data. Subscription messages are calculated by multiplying the number of published messages by the number of subscriptions. Both filtered and delivered messages are included in the count of subscription messages.  

  • Publish and publish batch API requests cost $0.30 per million requests and $0.017 per GB of payload data.  
  • Subscription messages are charged at $0.01 per million and $0.001 per GB of payload data.  
  • Topic owner and subscription owner API requests are billed at the same rate as Standard API requests. 

Note: Each message ranging from 1KB to 256KB is billed as one message. Any message smaller than 1KB is rounded up to 1KB for billing purposes. 

Note that the above pricing may vary depending on the region. 

Amazon SNS – Use Cases 

Application Alerts and Notifications: To send real-time alerts and notifications to users or system administrators. An e-commerce platform sends notifications about order status updates, shipping details, or promotional offers to its users. 

Decoupling Microservices: To decouple microservices within a distributed system. An order-processing service in an e-commerce application publishes an event to an SNS topic when a new order is placed, which triggers inventory, billing, and shipping microservices independently. 

Push Notifications for Mobile and Web Applications: Send push notifications to mobile devices or web applications. A news application sends breaking news alerts or personalized content notifications to users’ mobile devices or browsers. 

Broadcasting Messages to a Large Audience: To broadcast messages to many subscribers. A government agency sends emergency alerts to the public via email, SMS, and other channels using SNS. 

To summarize the use cases for Amazon SNS, Standard topics offer versatility and support multiple protocols like SQS, Lambda, HTTP, and more, but do not guarantee message order. FIFO topics, while limited to Amazon SQS, ensure strict first-in, first-out delivery. The choice depends on business needs for performance versus order guarantee. 

Amazon SNS – Demo 

We will see the demo to send messages to the mobile number with the help of Amazon SNS. 

  1. Go to the management console and open the SNS service. https://ap-south-1.console.aws.amazon.com/sns/v3/home?region=ap-south-1#/homepage 

Amazon SNS Dashboard 

  1. Create a topic by providing a topic name. We can also select the option Topics from the left menu to create a topic. 

Topics 

  1. Once we click on the Topics or Next Step, the Create Topic screen is displayed. Select the Topic type and add all the required details. In this demo, we will create a Standard Topic. Once filled in all the details, click on the Create topic button. 

Create Topic Form 

  1. Upon successful creation, a List of topics is displayed. Now we need to select a created topic and add a Subscription. 

List of Topics 

Create Subscription 

  1. We can add Email, HTTP, HTTPS, SMS, and more as a protocol. In this demo, we will add SMS as a subscription protocol and fill in required details. Once the required details are filled in, Click on Create subscription

Add Protocol 

  1. As we are creating Amazon SNS in the Sandbox environment, we need to verify the mobile numbers where we want to send the messages from the Amazon SNS. Click on the Add phone number option and a new screen will be opened. 
  1. Add the destination phone number along with the country code and click on the Add phone number

Add Phone Number 

  1. Once we add a phone number, Amazon SNS automatically hits a verification message that consists of a verification code. Upon successful verification, an entered number will be added to the Sandbox. Now we can create a subscription with the verified number. 
  1. Once everything is verified and added, the Topic looks as below. 

 Amazon SNS Topic Dashboard 

  1. To produce messages and pass them to all the subscribers, click on the Publish message button at the top right. Fill in all required details, and click on the Publish message

Text Message Form 

  1. The text message looks like below. Published messages will be shared with all the subscribers. 

Received Message from Amazon SNS 

This is how we can utilize Amazon SNS to send notifications via SMS. 

Conclusion 

Amazon Simple Notification Service (SNS) is a versatile, fully managed messaging service that simplifies the process of sending notifications across distributed systems, microservices, and serverless applications. It supports various protocols, including SMS, email, and HTTP/S, making it ideal for broadcasting messages, such as service status updates, application alerts, and mobile push notifications. With SNS, businesses can implement event-driven architectures, triggering actions across different systems in response to specific events, all while ensuring real-time communication with users and stakeholders. 

Author

Leave a Comment

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

Latest Blogs

SEND US YOUR RESUME

Apply Now