I wan't to kill a specific instance when some of it's hardware consumption metrics reaches a certain level. If i create an alarm for the scaling group (setting maximum cpu consumption threshhold to >=50 for example) it will kill the oldest instance - not the one that is misbehaving. One way to kill a specific instance is to create an alarm for the instance instead of creating it for the scaling group. However, if i launch a new instance (with autoscaling), this new instance will not have the alarm.

Is there a way to launch instances with preconfigured ec2 level alarms?

  • 1
    There are several termination policies you can use besides the default, but I'm afraid that none of them would necessarily work for your use case. You may need to do your own scaling. Have you thought about using user-data to have the new instance itself set an alarm with the AWS CLI? – Anthony Neace Jul 14 '14 at 19:47
  • No i have not. This is a good suggestion. I will end up doing that if i don't find another way of achieving what i need. – tulio84z Jul 14 '14 at 20:49

Cloudformation's AWS::CloudWatch::Alarm is useful for setting up machine-specific alarms. It's especially great combined with autoscaling, ELB, and EC2 instances. Here's a snippet used with an autoscaling group. Perhaps someone can suggest an edit to give an EC2-specific example.

"appCPUAlarmHigh": {
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "EvaluationPeriods": "7",
    "Dimensions": [
        "Name": "AutoScalingGroupName",
        "Value": {
          "Ref": "appServerGroup"
    "AlarmActions": [
        "Ref": "appStatusTopic"
    "AlarmDescription": "Notify if CPU high for >  7m",
    "Namespace": "AWS/EC2",
    "Period": "60",
    "ComparisonOperator": "GreaterThanThreshold",
    "Statistic": "Average",
    "Threshold": "50",
    "MetricName": "CPUUtilization"

Otherwise, you could roll something with Cloudinit and mon-enable-alarm-actions. Or OpsWorks using, uh, I don't know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.