AWS CloudWatch Alarms to multiple EC2 instances

2019-06-15 07:57发布

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

3条回答
爷、活的狠高调
2楼-- · 2019-06-15 08:17

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.
查看更多
何必那么认真
3楼-- · 2019-06-15 08:38

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

查看更多
来,给爷笑一个
4楼-- · 2019-06-15 08:38

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

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

查看更多
登录 后发表回答