The following is my favorite example for AutoScaling based on CPU utlization

Notes:

  • I prefer the cool down to be 10 minutes to let the started instance enough time to initilize
  • Make sure that the specified AZ are enabled in ELB, oterwize health check will fail

How to:

Step 1:

as-create-launch-config AS-CONF-[name] –image-id [ami-id] –instance-type [instance-type] –group [sec-group] –key [key-pair]

Step 2:

as-create-auto-scaling-group AS-GRP-[name] –launch-configuration AS-CONF-[name] –availability-zones us-east-1a us-east-1b us-east-1c us-east-1d –min-size 1 –max-size 3 –load-balancers [ELB-Name]

Step 3:

as-put-scaling-policy AS-PL-UpScale-[name] –auto-scaling-group AS-GRP-[name] –adjustment=1 –type ChangeInCapacity –cooldown 600

Step 4:

mon-put-metric-alarm AS-HighCPUAlarm-[name] –comparison-operator GreaterThanThreshold –evaluation-periods 1 –metric-name CPUUtilization –namespace “AWS/EC2” –period 600 –statistic Average –threshold 80 –alarm-actions [POLICY-ARN_from_previous_step] –dimensions “AutoScalingGroupName=AS-GRP-[name]”

Step 5:

as-put-scaling-policy AS-PL-DownScale-[name] –auto-scaling-group AS-GRP-[name] –adjustment=-1 –type ChangeInCapacity –cooldown 600

Step 6:

mon-put-metric-alarm AS-LowCPUAlarm-[name] –comparison-operator LessThanThreshold –evaluation-periods 1 –metric-name CPUUtilization –namespace “AWS/EC2” –period 600 –statistic Average –threshold 40 –alarm-actions [POLICY-ARN_from_previous_step] –dimensions “AutoScalingGroupName=AS-GRP-[name]”

Download the example

Lahav Savir

Founder and CTO, Cloud Platforms

Read more posts by Lahav Savir