How does Amazon SNS work?
Amazon SNS is quite simple to use.
- To publish messages and allow clients to subscribe to alerts, developers must first construct a "topic," which is an "access point" defining a certain subject or event type.
- After creating a topic, the subject owner can define its policies, such as who can publish messages or subscribe to alerts or which notification protocols will be supported (e.g., HTTP/HTTPS, Email, SMS).
- Subscribers are clients who want to be notified about subjects of interest; they can subscribe to a topic or be subscribed to by the topic owner. Subscribers indicate the protocol and Endpoint (URL, email address, etc.) to which alerts should be sent.
-
When publishers have information or changes to share with their subscribers, they can publish a message to the subject, which immediately sends it to all relevant subscribers.
Also see, Amazon Hirepro
Getting started with Amazon Simple Notification Service
Creating a topic
- Log in to your Amazon SNS console.
- Select Topics from the left navigation window.
- Select Create subject from the Topics page.
- The console produces a FIFO topic by default. Select Standard.
- Enter a name for the subject in the Details area, such as MyTopic.
- Scroll to the bottom of the form and select Create topic.
- The Details page for the newly formed subject is displayed in the console.
Creating a subscription to the topic
- Select Subscriptions from the left navigation pane.
- Select Create subscription from the Subscriptions page.
- Choose the Topic ARN field on the Create subscription page to get a list of the subjects in your AWS account.
- Select the subject you established in the preceding step.
- Select Email as the protocol.
- Enter an email address that may receive alerts for Endpoint.
- Select Create subscription.
- The console displays the new subscription's Details page.
- Check the email inbox and click Confirm subscription in the AWS Notifications email. Typically, the sender ID is "no-reply@sns.amazonaws.com."
- Amazon SNS opens your browser and displays a subscription confirmation page with the subscription ID.
Publishing a message on the topic
- Select Topics from the left navigation window.
- Select the subject you established previously on the Topics page, and then select Publish message.
- The console displays the page Publish message to the topic.
-
Enter a Subject in the Message Details field, such as
Welcome to Coding Ninjas!
It is an optional step and is just done here for testing.
5. Choose the Identical payload for all delivery methods in the Message body box, and then add a message body, such as
Publishing message to SNS topic.
6. Select Publish message.
7. The message is published to the subject, and the console displays the Details page for the topic.
8. Examine your inbox to see if you received an email from Amazon SNS with the published message.
Features of Amazon Simple Notification Service
-
Sources and destinations for events
Event-driven computing is a computing model in which subscriber services perform work automatically in response to events triggered by publisher services. This paradigm can be used to automate workflows while decoupling the services that work together and separately to fulfill these workflows. Amazon SNS is an event-driven hub that integrates natively with a wide range of AWS event sources and destinations.
-
Message publishing and batching
Message publishing allows you to send data in the form of messages to an Amazon SNS topic, which then delivers the messages to applications that have subscribed to the topic asynchronously. Per API request, you can publish up to ten messages. You can reduce your Amazon SNS costs by batching messages together. Each message can hold up to 256KB of information. If your use case necessitates larger data payloads, the Amazon SNS Extended Client Library can store the payload up to 2GB in the Amazon S3 bucket and publish the Amazon S3 object reference to the Amazon SNS topic.
-
Message filtration
Message filtering allows your subscriber applications to create filter policies, allowing them to receive only the notifications that they are interested in, rather than every message published on the topic. You can simplify your architecture by offloading message filtering logic from subscriber applications and message routing logic from publisher applications.
-
Message fanout and delivery
When a message to a topic is published, Amazon SNS replicates it and distributes it to applications that have subscribed to the topic. Amazon SNS supports message delivery from application to application (A2A) and application to person (A2P). Amazon SNS also supports cross-region and cross-account message delivery, as well as Amazon CloudWatch message delivery status logging.
-
Message durability
Amazon SNS employs a number of mechanisms that work in tandem to ensure message durability. To begin, published messages are stored across multiple servers and data centers that are geographically separated. When a subscribed endpoint is unavailable, Amazon SNS implements a message delivery retry policy. You can use a dead-letter queue powered by Amazon SQS to save any messages that aren't delivered before the delivery retry policy expires.
-
Encryption of messages
Amazon SNS offers encrypted topics to keep your messages safe from unauthorized and anonymous access. When you publish messages to encrypted topics, Amazon SNS encrypts them immediately. The encryption occurs on the server, and it employs a 256-bit AES-GCM algorithm and a Customer Master Key (CMK) issued by AWS Key Management Service (KMS). Messages are encrypted and delivered to subscribing endpoints such as Amazon SQS queues, Amazon Kinesis Data Firehose streams, AWS Lambda functions, HTTP/S endpoints, phone numbers, mobile apps, and email addresses.
-
Message confidentiality
AWS PrivateLink allows Amazon SNS to support VPC Endpoints (VPCE). You can use VPC Endpoints to publish messages to Amazon SNS topics without leaving your Amazon Virtual Private Cloud (VPC) privately. This feature adds security, promotes data privacy, and aligns with assurance programs. AWS PrivateLink eliminates the need for an Internet Gateway (IGW), Network Address Translation (NAT), or Virtual Private Network (VPN) connection. You are also not required to use public IP addresses.
-
Text messages (SMS)
Amazon SNS allows you to send SMS text messages to 200+ countries at scale, using a highly available and durable service with redundancy across multiple SMS providers. You can control your originating identity with Amazon SNS by using a sender ID, long codes, or shortcodes. You can also use the Amazon SNS sandbox to test your SMS workloads before deploying them to production.
-
Push notifications for mobile devices
Amazon SNS mobile notifications make it easy and inexpensive to distribute mobile push notifications to iOS, Android, Fire, Windows, and Baidu devices. User-driven actions or business logic can both mobile trigger notifications. Amazon SNS sends push notifications to mobile devices via Amazon Device Messaging (ADM), Apple Push Notification Service (APNs), Baidu Cloud Push (Baidu), Firebase Cloud Messaging (FCM), Microsoft Push Notification Service for Windows Phone (MPNS), and Windows Push Notification Services (WNS).
-
Notifications via Email
Amazon SNS allows you to send notifications to email addresses that have subscribed to topics. This feature is useful in a variety of situations. You can, for example, use Amazon SNS to receive application alerts as email notifications in order to gain visibility into your DevOps workflows. As a result, you can receive immediate notification when an event occurs, such as a specific change to your Amazon EC2 Auto Scaling group, a new file uploaded to your Amazon S3 bucket, or a metric threshold breached in Amazon CloudWatch.
Benefits of Amazon Simple Notification Service
Amazon SNS provides various advantages that make it a versatile choice for developing and integrating loosely linked distributed applications:
- Simplify and reduce costs with message filtering and batching APIs that are easy to use and integrate with apps
- Ensure accuracy with message ordering and deduplication
- Increase security with message encryption and privacy
- Increase durability with message archiving, delivery retries, and DLQ
- Capture and fan out events from AWS services
- Send A2P notifications via SMS, mobile push, and Email.
Frequently Asked Questions
What are the different topic types in Amazon SNS?
There are two types of topics in Amazon SNS:-
-
Standard topics
Standard topics can be used in a variety of scenarios, as long as your application can process messages that arrive multiple times and in a random order, such as fanning out messages to media encoding, fraud detection, tax calculation, search index, and critical alerting applications.
-
FIFO topics
FIFO topics are intended to improve messaging between applications when the order of operations and events is critical, or duplicates are not tolerated, such as when fanning out messages to bank transaction logging, stock monitoring, flight tracking, inventory management, and price update applications.
Can many users publish the same topic?
A topic owner can grant explicit access to multiple users (with a valid AWS ID) to publish to a subject. Only topic owners have the ability to publish to a topic by default.
Will I receive messages in the order in which they were published?
The Amazon SNS service will try to send messages from the publisher in the order in which they were published in the subject. However, network difficulties may cause out-of-order messages at the subscriber end.
Conclusion
In this article, we have extensively discussed the concepts of Amazon Simple Notification Service. We started with getting an overview of Amazon SNS. After that, we talked about its work, and then we created and published an Amazon SNS topic. We also learned about the features of Amazon SNS and finally concluded with the benefits of Amazon SNS.
You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and Algorithms, Competitive Programming, System Design, and many more! You may also check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! For placement preparations, you must look at the problems, interview experiences, and interview bundle.
Nevertheless, you may consider our paid courses to give your career an edge over others!
Happy Coding!