Introduction

Today, let’s see a simple yet useful AWS service and how we can use it to send emails. 

What is AWS SNS? Or Simple Notification Service?
This is to send and receive notifications to and from the receiver. SNS follows the publisher and subscriber model, the publisher-subscriber model commonly known as the PubSub model; the publisher is the producer of the messages, and the subscriber is the consumer of the messages. When the message is published on a topic, the sender of the message doesn’t need to know who is the receiver of the message and the subscriber too, does not know who is the sender of the message; as a result, this quality of SNS helps to make a more stable and scalable infrastructure. Change in the number of senders or receivers does not impact the overall architecture of the application.

The above diagram is a simple representation of how SNS AWS services work at the very base level. The diagram shows that the message sent is in the form of Emails, but we can do even more using SNS, like integrating it with other AWS services including – AWS Lambda, SQS (Simple Queue Service) HTTP/HTTPS protocols, etc. Today, in this blog, we will see how we can use SNS to send emails.

Steps to Send Email Using SNS

      • We will start with creating a Topic for our SNS service.
        What is the SNS topic?
        A topic is a type of channel that sends the messages sent by the publisher to all the subscribers. It works as a broker for us.

    Start by searching for SNS in the AWS console. You will be able to see the above page. In the Create Topic section, you will have to name the topic – you can name anything you want (we have given it as CloudZeniaDemo).

        • Once we are done creating the topic, we need to create our subscription, where we will be receiving our emails.
          To create a subscription, scroll down, and you will find the option to create a subscription. Click on Create Subscription.

          • Click on the drop-down list to select protocol; we will be using Email as our protocol. We are using Dispostable for receiving the email for this demo; you should choose the required email account to receive the emails. Then, click on Create Subscription.

            • Once you click on Create the subscription, an email by AWS is sent to your account, and you need to confirm the subscription. In case you do not receive any email, try clicking Request Confirmation. Once you have confirmed your subscription, we can move to our next step.

          We are now all set to send the message using AWS SNS. Inside the Topic Section, click on the “Publish” message.

          For this demo, we are not going to do anything fancy; we will see how we can send a simple message to the subscribed account. Enter your message details and subject, and then inside the Message body, enter your message. Then click on Publish Message. Voila! You’re done!

          You can cross-check in your account that you have used as a subscription.

          Congratulations! You have successfully learned how to use AWS SNS service and send messages; we can do much more using SNS, and combining it with other services can be a real game changer for the notification service. You can use SNS with Cloudwatch to directly send email notifications when any of your services are in alarming condition, and there are endless use cases.

          Here is a gif of the whole process that we have gone through; you can always go through it in case of any confusion.

          Conclusion

          This was a short and to-the-point blog on how we can use AWS SNS for sending emails. There are endless possibilities with this service. It is up to you what AWS SNS is in your use case. 

          If you face any difficulty deciding how we can leverage such AWS services in our infrastructure. We at CloudZenia are always here to assist you. Thanks for reading the blog, hope to see you next time.

          Till then, Happy Learning! 

          Jan 16, 2024