AWS Autoscaling How To
3/23/2012 05:26:00 PM
Posted by johnhomer
- Setup autoscaling and cloudwatch CLI
cd /home/john && mkdir ec2 && cd ec2 wget http://ec2-downloads.s3.amazonaws.com/AutoScaling-2011-01-01.zip unzip AutoScaling-2011-01-01.zip wget http://ec2-downloads.s3.amazonaws.com/CloudWatch-2010-08-01.zip unzip CloudWatch-2010-08-01.zip export EC2_HOME=/home/john/ec2 export PATH=$PATH:$EC2_HOME/bin export JAVA_HOME=/usr export EC2_PRIVATE_KEY=/home/john/pk.pem # You need to get this file from your AWS Credentials export EC2_CERT=/home/john/cert.pem # You need to get this file from your AWS Credentials export AWS_AUTO_SCALING_HOME=$EC2_HOME/AutoScaling-1.0.49.1 export AWS_AUTO_SCALING_URL=https://autoscaling.us-east-1.amazonaws.com export PATH=$PATH:$AWS_AUTO_SCALING_HOME/bin export AWS_CLOUDWATCH_HOME=$EC2_HOME/CloudWatch-1.0.12.1 export PATH=$PATH:$AWS_CLOUDWATCH_HOME/bin
- Setup variables
EC2_REGION="us-east-1" ZONE="us-east-1d" SECURITY_GROUP="default" INSTANCE_SIZE="t1.micro" LB_NAME="autoscalelb" LC_NAME="autoscalelc" LC_IMAGE_ID="ami-31814f58" # Could be any AMI of choice LC_KEY="john-east" # You need to create this key in the AWS console SG_NAME="autoscalesg" UP_POLICY_NAME="MyScaleUpPolicy" DOWN_POLICY_NAME="MyScaleDownPolicy" HIGH_CPU_ALRM_NAME="MyHighCPUAlarm" LOW_CPU_ALRM_NAME="MyLowCPUAlarm" MIN_SIZE=1 MAX_SIZE=4 # For testing purposes, set to 1 DOWN_THRESHOLD=40 # scale down when average CPU load is 40% or below UP_THRESHOLD=80 # scale up when average CPU load reaches 80%
- Create Launch Config
as-create-launch-config $LC_NAME --image-id $LC_IMAGE_ID --instance-type $INSTANCE_SIZE --group $SECURITY_GROUP --key $LC_KEY --block-device-mapping '/dev/sda2=ephemeral0' --user-data-file ud.txt
- Create Autoscaling Group
as-create-auto-scaling-group $SG_NAME --availability-zones $ZONE --launch-configuration $LC_NAME --min-size $MIN_SIZE --max-size $MAX_SIZE --load-balancers $LB_NAME
- Trigger scaling up
ARN_HIGH=`as-put-scaling-policy $UP_POLICY_NAME --auto-scaling-group $SG_NAME --adjustment=1 --type ChangeInCapacity --cooldown 300` mon-put-metric-alarm $HIGH_CPU_ALRM_NAME --comparison-operator GreaterThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 600 --statistic Average --threshold $UP_THRESHOLD --alarm-actions $ARN_HIGH --dimensions "AutoScalingGroupName=$SG_NAME"
- Trigger scaling down
ARN_LOW=`as-put-scaling-policy $DOWN_POLICY_NAME --auto-scaling-group $SG_NAME --adjustment=-1 --type ChangeInCapacity --cooldown 300` mon-put-metric-alarm $LOW_CPU_ALRM_NAME --comparison-operator LessThanThreshold --evaluation-periods 1 --metric-name CPUUtilization --namespace "AWS/EC2" --period 600 --statistic Average --threshold $DOWN_THRESHOLD --alarm-actions $ARN_LOW --dimensions "AutoScalingGroupName=$SG_NAME" #Post notifications to SNS (needed for dynamic registration) as-put-notification-configuration $SG_NAME --topic-arn arn:aws:sns:us-east-1:123456789012:topic01 --notification-types autoscaling:EC2_INSTANCE_LAUNCH, autoscaling:EC2_INSTANCE_TERMINATE
- Pausing and Restarting autoscaling activities
as-suspend-processes $SG_NAME as-resume-processes $SG_NAME
- Expand to other Availability Zones
as-update-auto-scaling-group $SG_NAME --availability-zones us-east-1a, us-east-1b, us-east-1c --min-size 3 elb-describe-instance-health $LB_NAME elb-enable-zones-for-lb $LB_NAME --headers --availability-zones us-east-1c
- Clean up
as-update-auto-scaling-group $SG_NAME --min-size 0 --max-size 0 as-delete-auto-scaling-group $SG_NAME as-delete-launch-config $LC_NAME mon-delete-alarms $HIGH_CPU_ALRM_NAME $LOW_CPU_ALRM_NAME
References
http://docs.amazonwebservices.com/AutoScaling/latest/DeveloperGuide/US_SetUpASLBApp.html
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
AWS,
cloud,
linux
. Follow any responses to this post through RSS. You can leave a response, or trackback from your own site.
Subscribe to:
Post Comments (Atom)
May 3, 2013 at 5:58 PM
Everything is fine, but where do you put the ud.txt file? It is work like a init script into the instance?
May 4, 2013 at 8:03 AM
hello, user-data is an optional parameter. But if you're doing autoscaling, you will need a user-data scrip almost all the time. You can put your user-data data script in your current working directory which ever folder you are working on.
September 29, 2016 at 9:38 PM
nice article