Continuing along with the course mentioned in the previous blog, the next part covered notification services using SNS. Simple Notification services or SNS are crucial when dealing with applications or data pipelines. They allow you to reliably send notifications directly to users for monitoring or alerting. In this blog, I will cover how SNS works and is used for SMS and email alerts.
In order to create an SNS topic, you must first initialize a Boto3 client for SNS. Initializing still requires a valid access key id and secret access key. Creating a topic is done by calling the create_topic method and stating the name for the new topic. This generates a unique identifier for the topic called a topicARN key. An important caveat to know is that creating topics with the same name as a topic that exists will return the ARN of the existing topic.
In order to list all the topics we are subscribed to, we call the list_topics method. We get a response listing all the topic ARN keys that we have access to. We can also delete a topic by calling in the delete_topic method and passing in the ARN key for the topic we wish to remove.
Each subscription to a topic has a unique ID (subscriptionARN), an endpoint, a protocol, and status. The delivery protocol refers to how the message is transmitted, such as email, http, or SMS (text messages). The endpoint is the specific address that the message should be sent to. The status of a subscription can either be ‘confirmed’ or ‘pending confirmation’. ‘Pending confirmation’ is used for emails and requires the user confirming the subscription through an separate email containing a confirmation link.
To create a subscription, we call the subscribe method and pass in the ARN, protocol, and endpoint we wish to use. Deleting subscriptions uses the unsubscribe method and pass in the subscriptionARN.
To publish a message to a topic, we use the publish method and pass in the topicARN, along with the message and subject as arguments. This message will then be broadcasted to the subscribers of the topic, who will receive notifications based on the delivery protocol. We also have the ability to send one-off messages to a phone number by simply specifying the phone number and message.
The final exercises for this part of the course were for a case study in building a notification system for critical issues for a City Council. We are asked to create a multi-level topic system(critical and extreme) for each city department based on the number of complaints. An extreme alert is considered more serious than a critical alert. A critical topic will alert the staff and managers of that department and an extreme topic will alert politicians and directors. Thus, we have different sets of subscribers depending on the threshold reached.
This was a very basic introduction to SNS as the course does not cover a number of features such as integration with other AWS services, message ordering/filtering, and topic encryption. However, Amazon does maintain documentation for the API to learn more about some of these features. In the next blog, I will look to cover more advanced services, specifically AWS Rekognition and Comprehend. Thanks for reading!