Tuesday, December 14, 2010

Amazon EC2 Auto Scaling

I setup Amazon Auto scaling which I found simple to setup and very effective.

Here are the list of commands that I used to setup from the command line :

(1) as-create-launch-config lc --image-id ami-9ecc3af7 --instance-type t1.micro -I amazonid -S secretkey
This command creates the launch configuration and references the AMI.


(2) as-create-auto-scaling-group group1 --launch-configuration lc --availability-zones us-east-1a --min-size 1 --max-size 2 --default-cooldown 180 --load-balancers  petstore --health-check-type ELB --grace-period 240 -I amazonid -S secretkey
This command sets up the auto scaling group.

(3) as-put-scaling-policy testScaleUp -g group1 --adjustment=1 --type PercentChangeInCapacity -I amazonid -S secretkey
This command sets up the auto-scaling policy. This command will return an arn number which will be used in the next command.

(4) mon-put-metric-alarm HighCPUAlarm --comparison-operator GreaterThanThreshold --metric-name CPUUtilization --namespace "AWS/EC2" --period 60 --statistic Average --threshold 5 --evaluation-periods 1 --dimensions "AutoScalingGroupName=group1" --alarm-actions arn:aws:autoscaling:us-east-1:868507589665:scalingPolicy:30b3c8d3-1b07-4064-b795-d196db923655:autoScalingGroupName/group1:policyName/testScaleUp -I amazonid -S secretkey

This command sets up the alarm to spawn new instances when CPU utilization goes above the threshold.

(5) as-put-scaling-policy testScaleDown --auto-scaling-group group1 "--adjustment=-1" --type ChangeInCapacity -I amazonid -S secretkey
This command sets up auto scaling policy for scaling down the instances. Also, this policy command will return an arn number which should be used in the next command.

(6) mon-put-metric-alarm LowCPUAlarm --comparison-operator LessThanThreshold --metric-name CPUUtilization --namespace "AWS/EC2" --period 60 --statistic Average --threshold 2 --evaluation-periods 3 --dimensions "AutoScalingGroupName=group1" --alarm-actions arn:aws:autoscaling:us-east-1:868507589665:scalingPolicy:44fa2f7a-b763-438c-b35a-18926b809182:autoScalingGroupName/group1:policyName/testScaleDown -I amazonid -S secretkey

This command sets up alarm for scaling down instances when the CPU utilization goes below the threshold.


Overall, the above 6 steps are required to setup the Amazon EC2 Auto Scaling in the application. You can play around with the lower and upper threshold cutoff to spawn and remove EC2 instances.

For more information on Auto Scaling, you can visit the Amazon AWS website.

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete