Creating a CloudWatch Alarm in AWS

You can create a CloudWatch alarm that sends a simple notification service message when the alarm changes the state. Alarm watches every single metric over a time period and hence performs actions depending on those metric values. Moreover, Amazon CloudWatch is a web service that enables you to monitor, manage, and publish various metrics and to configure alarm actions based on those metrics. With Amazon CloudWatch, you can collect, analyze, and view system and application metrics so that you can make operational and business decisions instantly and confidently. Amazon CloudWatch automatically collects metrics about your AWS resources, such as the performance of your Amazon EC2 instances. You can publish your own metrics directly to Amazon CloudWatch.

After an alarm invokes an action due to a change in the state, its subsequent behavior depends on the type of action that you have associated with the alarm. For Auto Scaling policy notifications, the alarm continues to invoke the action for every period that the alarm remains in the new state. For Amazon Simple Notification Service notifications, no additional actions are invoked.

You can use Amazon CloudWatch to diagnose problems by looking at system performance before and after a problem occurs. Amazon CloudWatch helps you identify the cause and verify your fix by tracking performance in real time. For example, you can set up Amazon CloudWatch to send you an email right away when your application slows down, so you can go back and discover, that a particular database was being overloaded. When you have fixed the problem, you can use Amazon CloudWatch to watch response times return to normal. For more information about creating CloudWatch alarms, go to Creating CloudWatch Alarms in the Amazon CloudWatch Developer Guide.

A common use for Amazon CloudWatch is to keep your applications and services healthy and running efficiently. For example, you can use it to discover that your website runs best when network traffic to your Amazon EC2 instances remains below a certain threshold. You can then create an Auto Scaling policy to ensure that you always have the right number of instances to match the amount of traffic you have.

In the previous task, we have created an Auto Scaling policy to add to the number of running instances. In this task, we’ll associate that policy with an alarm action. When the alarm is triggered, Auto Scaling is notified and makes the appropriate changes to your resources.

An alarm has three feasible states:

OK – which means the metric is within the threshold limit

ALARM- means metric has gone outside the defined threshold limit

INSUFFICIENT_DATA- means enough data is not available for the metric to determine the alarm state

You’ll create an alarm with the following characteristics:

The following diagram demonstrates how Amazon CloudWatch and Auto Scaling would work together. The Amazon EC2 instance, reports its Network Out metric to Amazon CloudWatch. Amazon CloudWatch fires an alarm if the specified threshold has exceeded and reports this to the Auto Scaling Group. The Auto Scaling group then takes action based on the policy that was set.

This topic walks you through creating a CloudWatch alarm to alert the application when the threshold is exceeded. To save time, we’ll create just one alarm; however, you can apply the same procedure to create other alarms. For example, you could create another alarm to notify Auto Scaling, that it needs to terminate at an instance. For more information about Amazon CloudWatch, see the Amazon CloudWatch details page.

To create an Amazon CloudWatch alarm

You can create an alarm from the Alarms list in the Amazon CloudWatch console.

Auto Scaling to automatically add and terminate instances according to the policies that you set.

Amazon CloudWatch to monitor your instances and to notify you when the thresholds you have specified had exceeded

When you have a better understanding of the AWS services and how you want to use them, there is an easier way you can deploy your application. AWS Cloud Formation helps you deploy resources in AWS without worrying about the order in which AWS services need to be provisioned or the subtleties of how to make those dependencies work. To learn how to build a sample template using the services we used in this tutorial, go to Auto Scaling Group with LoadBalancer, Auto Scaling Policies, and CloudWatch Alarms in the AWS Cloud Formation User Guide. If you are finished using your AWS resources, you can terminate them so that you are no longer billed. Move on to further post titled ‘Clean Up‘.