Create a CloudWatch Alarm
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.
Amazon CloudWatch can monitor AWS resources such as Amazon EC2 instances, Amazon Dyanamo DB tables and Amazon RDS DB instances.
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:
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.
1. Select a metric for your alarm:
Note: It might take up to 15 minutes for the Auto Scaling group to appear in the list. If you do not see your Auto Scaling group, wait up to 15 minutes, and then try again.
2. Define the alarm:
On the Define Alarm page of the Create Alarm wizard, do the following, and then click Continue:
3. Define your actions:
a) On the Configure Actions page of the Create Alarm wizard, do the following, and then click Add Action.
b) Do the following, and then click Continue.
4. On the review page, review the settings. If everything is all right, click ‘Create Alarm’.
5. On the confirmation page, click close.
On the dashboard page of the Amazon CloudWatch console, your new alarm now appears in the list.
If you create a MyScaleDownPolicy, you can create another alarm using the same steps.
Where You’re At
Here’s where you are building your architecture.
Congratulations! You have successfully deployed your web application to EC2 by using some of the essential building blocks of AWS. To verify that everything is working as it should, do the following:
In this tutorial, you have learnt how to deploy your web application by using the following AWS products:
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‘.
|AWS Certified SysOps Administrator||AWS Certified Solutions Architect / Professional|
|AWS Certified Developer||AWS Certified DevOps Engineer|
|AWS Technical Essentials||AWS Database Migration Service|
|AWS Lambda 2016||and many more...|
Get Updates on Tech posts, Interview & Certification questions and training schedules