Amazon Simple Notification Service (SNS) is used for the Application to Application (A2A) and Application to Person (A2P) communication. It provides developers with a highly scalable, flexible, and cost-effective capability to publish messages from an application and immediately deliver them to subscribers or other applications. Using AWS Console it is easy to publish messages to your endpoint of choice (HTTP, SQS, Lambda, mobile push, email, or SMS) and edit topic policies to control publisher and subscriber access.
Advantages of SNS:
- Immediate, push-based delivery
- Easy for integration
- Flexible message delivery using protocols
- It supports FIFO topics
Steps to create AWS SNS Service:
The below Steps are related to AWS E-mail SNS Service.
- Firstly, open the AWS cloud shell and use the following command for creating the topic. Specify the name of the topic, for example, gfg-topic:
$ aws sns create-topic --name gfg-topic
- Subscribe to the Topic:
$ aws sns subscribe --topic-arn arn:aws:sns:us-west -2:123456789012:gfg-topic --protocol email --notification-endpoint example@example.com
- Here you can choose your protocol to send your message through which protocol. i.e., HTTP, SQS, Lambda, mobile push, email, or SMS. After running the command you will get the email, to confirm your subscription by clicking on the given link.
- Publish to a topic: After subscribing to the topic publish your topic and send the message to a perspective person or device.
$ aws sns publish --topic-arn arn:aws:sns:us-west-2:123456789012: gfg-topic --message "Hello Geeks"
- Unsubscribe the Topic: For stopping receiving messages from the particular application you can unsubscribe using this command:
$ aws sns unsubscribe --subscription-arn arn:aws:sns:us-west-2:123456789012: gfg-topic:1328f057-de93-4c15-512e-8bb22EXAMPLE
- Delete the topic: For deleting the topic you can simply use the below command:
$ aws sns delete-topic --topic-arn arn:aws:sns:us-west-2:123456789012:gfg-topic