Setup Amazon Simple Notification Service -AWS SNS
Tags: aws, awscommunitybuilders, cloud, community
Published: 2023-05-02 10:19:22


**Outline**

Introduction to SNS in AWS
SNS Topics and Subscriptions
SNS Message Filtering
SNS Mobile Push Notifications
SNS Email Notifications
Benefits of SNS
Security and Compliance
Integration with Other AWS Services
Create Amazon Simple Notification Service (AWS SNS)


**Introduction to SNS in AWS**

Amazon Simple Notification Service (Amazon SNS) is a managed service that provides message delivery from publishers to subscribers (also known as producers and consumers). Publishers communicate asynchronously with subscribers by sending messages to a topic, which is a logical access point and communication channel. Clients can subscribe to the SNS topic and receive published messages using a supported endpoint type, such as Amazon Kinesis Data Firehose, Amazon SQS, AWS Lambda, HTTP, email, mobile push notifications, and mobile text messages (SMS).


Application to Application (A2A)subscribers:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jhf0snyq6grvhqmonyh.png)


**SNS Topics and Subscriptions** 

In SNS, messages are published to a topic, which is an access point for subscribers to receive notifications. A topic can have multiple subscriptions, each representing a unique endpoint that receives messages. Subscribers can be added or removed dynamically without affecting the publisher or other subscribers. This makes SNS highly flexible and scalable, allowing users to easily adapt to changing requirements.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtqrygmlodbchywcqikr.png)

**SNS Message Filtering**

SNS provides powerful filtering capabilities that allow subscribers to receive only relevant messages based on their interests. Filters can be based on message attributes, message content, or a combination of both.
This feature helps reduce unnecessary message processing and improves the efficiency of the system. It also enables targeted messaging, allowing users to send personalized messages to specific groups of subscribers.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/df25xl5wu5cm5cttbjkj.png)


**SNS Mobile Push Notifications**

SNS supports mobile push notifications for iOS, Android, Kindle Fire, and Windows devices. It provides a simple and cost-effective way to send push notifications to millions of mobile devices at scale.
SNS integrates with popular mobile application platforms such as Amazon Pinpoint, Firebase Cloud Messaging, and Apple Push Notification Service (APNs) to provide a seamless experience for developers.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v4dukma7105pu6axrr1h.png)




**SNS Email Notifications** 

SNS can also send notifications via email, allowing users to receive important updates directly in their inbox. It supports both HTML and plain text formats, and allows customization of the email subject and body. In addition, SNS provides built-in support for bounce and complaint handling, making it easy to manage email deliverability and maintain sender reputation.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cakmkdjttz4rsnnkwt7v.png)


**Benefits of SNS**

SNS provides several benefits to businesses, including high throughput, low latency, and scalability. With SNS, businesses can send millions of messages per second to multiple recipients without worrying about message loss or delay.
Moreover, SNS is highly available and durable, ensuring that messages are delivered reliably. Businesses can also use SNS to segment their customer base and send targeted messages based on user preferences.

**Security and Compliance**

SNS provides several security features, including encryption at rest and in transit, IAM roles and policies, and VPC endpoints. Businesses can also use SNS to comply with regulatory requirements such as HIPAA and GDPR.
Additionally, SNS provides detailed logging and monitoring capabilities, enabling businesses to audit message delivery and troubleshoot issues effectively.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2qqb1i5vt17eo21fnfdr.png)


**Integration with Other AWS Services**

SNS integrates seamlessly with other AWS services such as Lambda, EC2, and S3. For example, businesses can use SNS to trigger Lambda functions, which can perform custom actions based on the received message.
Moreover, SNS can be used to notify administrators of system events or errors, enabling them to take timely action to resolve issues.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2k987dkbu8gp6mq5m8vb.png)

**Create Amazon Simple Notification Service (AWS SNS):** 

**Step 1: Create a topic** 

Sign in to the Amazon SNS console: From the Amazon console in your AWS account management, select Simple Notification Service through the search box or through Services:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ma593se6u14q7ha6iw07.png)

- The Amazon SNS dashboard displays resource details for the region selected in your account.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ldg2v2zx2z8jejqc7ic8.png)



- On the **Topics** page, choose **Create topic**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n3guaylnx3lgkckisyeu.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jw9q64ltdqhj4gag0ala.png)

- In the **encryption** section, if you choose Enabling server-side encryption add at-rest encryption to your topic. Amazon SNS encrypts your message as soon as it is received. The message is decrypted immediately prior to delivery.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kkdfzlzq8ozchyym068.png)

- In the **Access Policy** section, the policy defines who can access your topic. By default, only the topic owner can publish or subscribe to the topic.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fasllnj0dwvmw8mzzf4j.png)

- Scroll to the end of the form and choose **Create topic**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/910dpx5lpa3mg7qbdx0m.png)

The console opens the new topic **Details** page. And it tells us that the topic was created successfully.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ob4av6ij0o36dgbuz13d.png)


**Step 2: Create a subscription to the topic** 
- On the **Subscriptions** page, choose **Create subscription**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dzovr164ooxo0g6vit37.png)

-On the **Create subscription** page, choose the **Topic ARN** field to see a list of the topics in your AWS account.
-Choose the topic that you created in the previous step. 
- For **Protocol**, choose **Email** (or any protocol you need).

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uw6ly63ij521qued1fli.png)

- For **Endpoint**, enter an email address that can receive notifications.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9gvejompn9iqkmn8e6ll.png)


- Choose **Create subscription**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ouqqph68ujp0dagqzepb.png)

The console opens the new subscription's **Details** page. And tells us that the subscription was created successfully.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4s71b6p28k14a8s53me0.png)

- Check your email inbox and choose **Confirm subscription** in the email from AWS Notifications.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/icqylazojsvow5srit2m.png)

- The sender ID is usually "no-reply@sns.amazonaws.com".

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mx4myx80laj4xg4flz51.png)

On the Subscription page: Subscription is pending.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kwccugqnhofq25mphypz.png)
And then confirmed.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3yzsoluve2fa11b9l14k.png)

**Step 3: Publish a message to the topic**

- In the left navigation pane, choose **Topics**.
- On the **Topics** page, choose the topic that you created earlier, and then choose **Publish message**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vmr5zpk8ykcafbc5ws0q.png)

-The console opens the **Publish message** to topic page.
-(Optional) In the Message **details section**, enter a **Subject**, such as: ‘ SNSTest’

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ooacaka6ccv5713uymrv.png)

- In the **Message body** section, choose **Identical payload for all delivery protocols**, and then enter a message body, such as:
‘ Hello Hello’

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f45zmp3jj0ne40yoron9.png)

In the message attribute: choose the type and put the name and value
- Choose **Publish message**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bf82gtmnmh26i1nk8aze.png)

The message is published to the topic, and the console opens the topic's **Details** page.

- Check your email inbox and verify that you received an email from Amazon SNS with the published message.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdq13vply1u06fctp97v.png)

**Step 4: Delete the subscription and topic** 

- On the navigation panel, choose **Subscriptions**.
-On the **Subscriptions** page, choose a confirmed subscription and then choose **Delete**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yl1ikpflizo5it8jc9xd.png)

**Note:** You can't delete a pending confirmation. After 3 days, Amazon SNS deletes it automatically.

- On the navigation panel, choose **Topics**.
- On the **Topics** page, choose a topic and then choose **Delete**.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h23x651o3ucl74t6qzgc.png)

**Important** 
When you delete a topic, you also delete all subscriptions to the topic.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xsnlosiyyx19zhh8jtw.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gaaj6ehle3mxqe11aisv.png)

**References:**

https://docs.aws.amazon.com/sns/latest/dg/welcome.html
https://docs.aws.amazon.com/sns/latest/dg/sns-getting-started.html