简体   繁体   中英

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

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

I don't believe this is possible - CloudWatch seems designed to be 'very manual' or 'very automated'. ie 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.

I think what you are actually looking for would be auto-scaling:

https://aws.amazon.com/documentation/autoscaling/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM