We can use Cloudwatch to view and analyze metrics for SNS Topics we have in our account. Cloudwatch can give us better insight into the performance of our SNS topics. Cloudwatch provides NumberOfMessagesPublished, NumberOfNotificationsDelivered, NumberOfNotificationsFailed and many more metrics for SNS Topics. In this article, we will see steps to create an alarm for the “NumberOfNotificationsDelivered” metric for the existing SNS Topic. The “NumberOfNotificationsDelivered” gives insight into a number of messages delivered successfully from the SNS topics to subscribing endpoints.

Before proceeding with this article, it is assumed that you already have an SNS Topic in the account. To create an alarm you must have a topic in the account. Also, if you want to get notified when the alarm is triggered, you must have an SNS Topic with a confirmed subscription to it. 

To know more about metrics provided by Cloudwatch for SNS visit the official documentation of AWS here.

Pre-requisites

  1. AWS Account(Create if you don’t have one).
  2. SNS Topic (Click here to learn to create an SNS Topic using Cloudformation)

What will we do?

  1. Login to AWS.
  2. Create an alarm for the SNS Topic.
  3. Delete the alarm.

Login to AWS

Click here to go to AWS login Page.

Enter your credentials to login into your account on the page you get when you click on the above link.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Once you successfully login into your AWS account you will see the main AWS management console as follows.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Create an Alarm for SNS Topic

To create an alarm for the existing SNS Topic, search for “Cloudwatch” in the search box at the top of the screen.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

You will see the main dashboard for Cloudwatch as follows. Click on the “Alarms” button in the left panel.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Since I do not have any alarm created in my account under the selected region, we do not see anything on this screen. To create an alarm click on the “Create alarm” button.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Click on the “Select metric” button to select the required metric for the SNS topic.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Search for “SNS” to filter metrics related to the SNS topics. Click on “Topic metrics” to proceed.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

On this page, you will see available metrics for the SNS topics you have in your account under the selected region. Here,  I have selected a “NumberOfNotificationsDelivered” metric for the “test” Topic. This metric checks for the number of notifications that have been delivered by the topic. Click on the “Select metric” button to proceed.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Here, you can specify a threshold type and a value for it. I have selected the threshold type as “static’, specified its value as “1” and the condition as “Greater/Equal”. This means if the number of messages that have been delivered by the topic is greater than or equal to 1 then the alarm will be triggered. 

Click on the “Next” button to proceed.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

If you want to send a notification then you can specify an SNS topic on which the notification will be sent if the condition becomes true. So in this case, if the number of messages that have been delivered by the SNS topic is greater or equal to 1 then a notification will be sent to the “test” SNS topic.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

On this screen, give a name to the alarm you are creating and optionally you can add a description to the alarm. Click on the “Next” button to proceed further.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

This is the last step where you can review your configurations before you create an alarm. Review all your configuration and then click on the “Create alarm” button.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

You can see your alarm if it gets successfully created. The alarm will take a few minutes to update its state, till then the state of the alarm will be “Insufficient data”.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Depending upon the condition, the state of the alarm will get updated. In this case, the condition matches and hence the state of the alarm goes to “In alarm”.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

As the alarm moves to the “In alarm” state it sends a notification to the Endpoint subscribed to the SNS specified in the configuration.

How to create Cloudwatch alarms for an SNS Topic on AWS linux Advertisement

You can also edit the alarm to update the threshold value. To edit the alarm, select the alarm and click on the “Actions — > Edit” button.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Here, I have changed the threshold value to “10” from “1” and updated the alarm.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

This time the condition does not match and the alarm transits to the “OK” state. It means the number of notifications delivered by the SNS topic is not greater than or equal to the value “10” we specified in the alarm.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Delete the Alarm

If you were just learning to create alarms and you no longer need the alarm you created in your account you can easily delete it.

To delete the alarm select it and click on the “Actions — > Delete” button.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Click on the “Delete” button on the pop-up screen you get to confirm the deletion. Once you delete the alarm you cannot restore it so be careful with the delete operation.

How to create Cloudwatch alarms for an SNS Topic on AWS linux

Conclusion

In this article, we saw the steps to create an alarm for the existing SNS topic in your account. We also saw how easily an alarm can be deleted in just a few clicks. One needs to be very careful while performing the delete operation since the delete operation deletes alarms permanently.