Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudWatch Alarms to multiple EC2 instances

I'm wanting to apply a CloudWatch alarm to stop instances which aren't being used in our pre-production environment. We often have instances being spun up, used and then left turned on which is really starting to cost us a fair amount of money.

CloudWatch alarms have a handy feature whereby we can stop based on some metrics - this is awesome and what I'd like to use to constantly keep an eye on the servers with but let it tidy up the instances for me.

The problem with this is that it appears that the CloudWatch alarms need to be created individually against each instance. Is there a way in which I can create one alarm which would share values across all current and future instances which will be started?

ETA - Alternatively, tell me that these options are better than CloudWatch and I'll be happy at that.

AWS EC2 stop all through PowerShell/CMD tools

like image 750
Adam W. Avatar asked Jan 23 '14 15:01

Adam W.


People also ask

How do you make a CloudWatch alarm for multiple instances?

Create an additional alarm for your EC2 instance using tagsOn the Tags tab, choose Manage tags, and then choose Add tag. For Key, enter AutoAlarm-AWS/EC2-StatusCheckFailed-GreaterThanThreshold-5m-Average. For Value, enter 1. Choose Save.

What three AWS services can receive CloudWatch alarm notifications?

Using Amazon CloudWatch alarms, you can set up metric thresholds and send alerts to Amazon Simple Notification Service (SNS). SNS can send notifications using e-mail, HTTP(S) endpoints, and Short Message Service (SMS) messages to mobile phones, and it can even trigger a Lambda function.

What is the best approach to monitor multiple EC2 instances?

You can monitor your instances using Amazon CloudWatch, which collects and processes raw data from Amazon EC2 into readable, near real-time metrics.

When you recover an AWS EC2 instance using CloudWatch alarm What happens to the instance?

If your instance fails a system status check, you can use CloudWatch alarm actions to automatically recover your instance. The recover option is available for over 90% of deployed Amazon EC2 instances. However, the recover option works only for system check failures, not for instance status check failures.


2 Answers

Add a startup script that creates the CloudWatch alarm to the base image you use to generate your VMs.

http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/CLIReference.html

like image 118
Chris Montanaro Avatar answered Oct 12 '22 13:10

Chris Montanaro


I don't believe this is possible - CloudWatch seems designed to be 'very manual' or 'very automated'. i.e. You can't setup one alarm which would go off if any one instance is idle, you have to setup individual alarms for each instance.

A couple of possible solutions, which are probably not what you want to hear:

  1. Script your instance creation, and add a call to cloudwatch to create an alarm for each instance.
  2. Run a service continually, which looks for instances and checks to ensure that there is an alarm for the instance, create alarms for the new instances, and remove alarms for instances which have been terminated.
like image 36
Daniel Scott Avatar answered Oct 12 '22 13:10

Daniel Scott