This can help if you are creating any kind of auto scale on Amazon AWS.
It is not a 100% automatic, as you will need to prior to running this have:
Pre-requisites on how to run the AWS command lines are here
1. The instance image setup just how you need it, and ami-id ref.
2. The loadbalancer created and configured to use zones us-east-1d,us-east-1a
After running the script
1. Create the CloudWatch Alarms I have been using EC2 Aggregated by Scale Group: HIGHCPU (add 1 instance) LOWCPU (remove 1 instance) you can also set the highcpu to send you an e-mail. You can also use HighLatency to add 1 instance.
Its easy to stress test (run on local) using stress tools like:
ab -n 100000 -c 500 http://lbtest-167232582091.us-east-1.elb.amazonaws.com/info.php
stress -v -c 1 -t 720
here is the script:

#!/bin/bash
# script to auto setup AWS Auto Escale configuration
# by Felipe Ferreira May 2013
#To work you must Create on GUI:
#The Load Balancer coniguratioin, using multiple zones
#The metrics using the auto escaling groups: 1. HighCPU(increase 1) 2.LowCPU(decrease 1) 3.HighLatency(increase 1)
#EDIT HERE
CONFIG="conf_lb_varnish"
IMAGE_ID="ami-a504375cc"
GROUP_SEC="varnish"
KEY="infografico_aws"
LB="lbvarnish"
GROUP="group_lb_varnish"
SERVER_NAME="amzvarnish00"
INSTANCE_SIZE="t1.micro"
DCAP=2
echo -e "\n Creaing AWS Auto Escale : \n config: $CONFIG all new auto images will be based on $IMAGE_ID \n and security-group $GROUP_SEC and key $KEY \n the new images will be auto inserted into the Load Balancer $LB \n"
echo -e "\nCreating launch-config $CONFIG ..."
as-create-launch-config $CONFIG --image-id $IMAGE_ID  --instance-type $INSTANCE_SIZE  --group $GROUP_SEC --monitoring-enabled --key $KEY
echo -e "\nCreating  scaling-group $GROUP  ..."
as-create-auto-scaling-group $GROUP --launch-configuration  $CONFIG  --availability-zones us-east-1d,us-east-1a --min-size 2 --max-size 6  --desired-capacity $DCAP --default-cooldown 180 --load-balancers $LB --health-check-type ELB --grace-period 240 --tag "k=Type,v=PRD,p=true" --tag "k=Name,v=$SERVER_NAME,p=true" --tag "k=ServerType,v=WEB-FE"
as-describe-auto-scaling-groups --headers && as-describe-launch-config --headers
echo -e  "\n Create the Trigers (new method: April 2013)"
ARN_P_UP=`as-put-scaling-policy policy-up --auto-scaling-group $GROUP --adjustment 1 --type ChangeInCapacity --cooldown 300`
ARN_P_DOWN=`as-put-scaling-policy policy-down --auto-scaling-group $GROUP --adjustment=-1 --type ChangeInCapacity --cooldown 300`
echo -e "Scaling up policy created ARN \n $ARN_P_UP"
echo -e "Scaling down policy created ARN \n $ARN_P_DOWN"
as-describe-policies
#echo -e "\nCreating the monitoring and associating with the  policy (this works better via GUI)\n"
echo -e "\nPlease Create the monitoring and associating with the  policy via GUI)\n"
as-describe-scaling-activities --show-long
#Note: It may come up with INSUFFICIENT_DATA (something went wrong with the creation of the monitoring, do it via GUI)
echo -e "\n To Delete do: \n"
echo " as-delete-policy policy-up --auto-scaling-group $GROUP"
echo " as-delete-policy policy-down --auto-scaling-group $GROUP"
echo " as-delete-auto-scaling-group $GROUP --force-delete"
echo " as-delete-launch-config $CONFIG "
echo -e "\n To Verify: \n"
echo " as-describe-scaling-activities --show-long"
echo  " as-describe-auto-scaling-groups $GROUP"
echo  " as-describe-policies "

Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *