17

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

Community
  • 1
  • 1
Adam W.
  • 193
  • 1
  • 2
  • 8
  • Here's one solution to this: http://stackoverflow.com/questions/13502491/can-a-cloudwatch-alarm-be-defined-for-a-metric-over-many-dimensions?rq=1 – Bhanu Chawla Jan 23 '14 at 16:10

3 Answers3

5

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

Chris Montanaro
  • 16,948
  • 4
  • 20
  • 29
  • 3
    -1. Your solution still creates an alarm per instance which NOT what OP wants. That's the essence of this question. How to create one alarm for a given metric and apply it to multiple instance. – slayedbylucifer Jan 24 '14 at 04:25
  • This could work. I think I should need to resign to the fact that CloudWatch won't work on an overall 'grouping' basis, but if I can apply a startup script and tie in with the AMI that I'm using to create the CloudWatch Alarm against itself, this overcomes most of the barriers. The only way I don't want to be doing this on an individual basis is if this is done manually. – Adam W. Jan 24 '14 at 10:28
4

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.
Daniel Scott
  • 7,418
  • 5
  • 39
  • 58
-4

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

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

Chris Montanaro
  • 16,948
  • 4
  • 20
  • 29
  • Nope, we're not. The nature of the instances is that they are used for specific tasks on an ad-hoc basis (different code bases, mainly) so auto-scaling wouldn't benefit this. – Adam W. Jan 23 '14 at 16:53
  • maybe set you shutdown behaviour to Terminate and have you task issue a shutdown after completion – Chris Montanaro Jan 23 '14 at 16:56
  • I can see the logic, but they typically aren't used for a single task. Sometimes they are being used for days, other times they are used for 10 minutes. It's an entirely flexible environment which is why I'm finding the 'stop all' options on my first question insufficient and getting complaints! – Adam W. Jan 23 '14 at 17:22
  • How is it determined that a node can be retired? – Chris Montanaro Jan 23 '14 at 17:36
  • It would be determined by the node having a period of inactivity. The CloudWatch metric I've identified would be the CPUUtilization. – Adam W. Jan 24 '14 at 10:27