CloudWatch metrics for SQS queues are collected and pushed to CloudWatch at one-minute intervals automatically. These metrics are provided at no charge in CloudWatch for both standard and FIFO queues. Following are the metrics available in Cloudwatch to view and analyze SQS queues.

  1. ApproximateAgeOfOldestMessage: This metric returns the approximate age of the oldest non deleted message in the queue.
  2. ApproximateNumberOfMessagesDelayed: This gives the number of messages in the queue that are not available for reading immediately and delayed. 
  3. ApproximateNumberOfMessagesNotVisible: It is the number of messages that are in flight, i.e. they have been sent to a client but not yet deleted or not yet reached to the client.
  4. ApproximateNumberOfMessagesVisible: It is the number of messages available in the queue for retrieval.
  5. NumberOfEmptyReceives: It is the count of ReceiveMessage API calls that did not return a message.
  6. NumberOfMessagesDeleted: This returns the number of messages deleted from the queue.
  7. NumberOfMessagesReceived: It is the number of messages returned by calls to the ReceiveMessage action.
  8. NumberOfMessagesSent: It is the number of messages added to a queue.
  9. SentMessageSize: This gives the size of messages added to a queue.

For more details on the available metrics, click here to visit the official documentation.

In this article, we will create an alarm for the “NumberOfMessagesSent” metric. Before we proceed, it is assumed that you have some basic understanding of SQS queues, SNS Topics. It is also assumed that you at least have 1 active SQS queue and an SNS topic with a subscription. 

Pre-requisites

  1. AWS Account(Create if you don’t have one).
  2. SQS Queue.
  3. 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 SQS queue.

Login to AWS

Click here to go to AWS Login Page.

You will see the login page as follows when you hit the above link. Enter your credentials to login into your AWS account.

<img alt="Login screen" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_104704_am.png606f429ec24e1.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Once you log in successfully into your account, you will see the main AWS Management Console as follows. Here, you can choose the desired region.

<img alt="AWS Management console" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_104903_am.png606f429f2058f.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Create an alarm for the SQS queue.

Search for “Cloudwatch” in the search box at the top of the screen.

<img alt="Search Cloudwatch" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_104918_am.png606f429f65b01.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="155" loading="lazy" src="data:image/svg xml,” width=”750″>

You will see the Cloudwatch dashboard as follows. This dashboard gives you an overview of Cloudwatch. You can give it a try and explore on your own as this is not in the scope of this article.

Click on “Alarms” in the left panel.

<img alt="Cloudwatch Dashboard" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_113822_am.png606f429fbbb30.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

If you have any existing alarms you will see them here. Make sure you are in the desired region.

To create a new alarm for an existing SQS Queue click on the “Create alarm” button. 

<img alt="Alarms screen" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_113847_am.png606f429ff16db.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="204" loading="lazy" src="data:image/svg xml,” width=”750″>

You will get a screen to specify a metric and conditions for the alarm to be created. Click on the “Select metric” button.

<img alt="Specify metric and conditions" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_113911_am.png606f42a045011.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="218" loading="lazy" src="data:image/svg xml,” width=”750″>

You’ll get a list of services with metrics available for them.

<img alt="Select metric" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_113942_am.png606f42a0b88e0.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

In the search box, search for SQS and you’ll get the filtered result as “SQS> Queue metrics”. Click on the SQS result.

<img alt="Browse SQS" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_113959_am.png606f42a121897.jpg" ezimgfmt="rs rscb3 src ng ngcb3" loading="lazy" src="data:image/svg xml,”>

On this screen, you will see available metrics for the queues you have in your account. Let’s select any one of these to create an alarm for it. Here, let’s proceed with the “NumberofMessagesSent” metric. Click on the “Select metric” button to proceed.

<img alt="Select metric" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_114050_am.png606f42a18d0d2.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Choose the Statistics, Threshold type, Condition, and Threshold value as per your choice. Here, the alarm will be triggered if the sum of the number of messages sent is greater than 5 for 5 minutes.

<img alt="Specify metric and conditions" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_114225_am.png606f42a20fb8a.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Choose the Alarm state Trigger, SNS Topic. When the alarm is triggered it will send a notification to the specified SNS topic.

<img alt="Configure actions" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_94319_pm.png606f42a28bdfc.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Give name and description to alarm and click on the “Next” button.

<img alt="Add name and description" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_114356_am.png606f42a304aa3.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="252" loading="lazy" src="data:image/svg xml,” width=”750″>

Review the configuration and click on the “Create alarm” button which will create an alarm.

<img alt="Preview and create" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_114409_am.png606f42a36e135.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="468" loading="lazy" src="data:image/svg xml,” width=”750″>

Now you can see the alarm we just created. The state of the alarm will change based on the threshold value and condition. 

<img alt="Alarm in OK state" data-ezsrc="https://kirelos.com/wp-content/uploads/2021/04/echo/screenshot_2021-04-03_at_114952_am.png606f42a3c464a.jpg" ezimgfmt="rs rscb3 src ng ngcb3" height="225" loading="lazy" src="data:image/svg xml,” width=”750″>

Conclusion

In this article, we created an alarm for the existing SQS queue. The alarm we created is triggered when the “Sum” of “NumberofMessagesSent” is “Greater” than the threshold value “5” for “5 minutes”, and when it is triggered a notification is sent to the SNS topic. You can now follow the same steps to create alarms for any other available metric, with different statistics and the threshold value.Advertisement