Amazon Autoscaling Tutorial

Amazon’s EC2 with autoscaling is a great way to maximize performance and minimize costs. Unfortunately the amazon autoscaling setup is only configurable via commandline which can make it seem a little daunting at first. Basic autoscaling is very simple, you only need a few items:

  • Launch Config – controls the ami, security group, and instance size
  • Autoscaling Group – controls the region, load balancer to attach to, minimum number of servers, and maximum number of servers
  • An EC2 server image to autoscale
  • An EC2 loadbalancer

Here is list of steps to get it up and running:

  1. Make an AMI of the server that you want to autoscale. Make sure that you can deploy code to it on the fly, using a tool such as Beanstalk for example.
  2. Make a loadbalancer if you don’t already have one
  3. Download the amazon autoscaling tools, the zip is named something like AutoScaling-1.0.61.0.zip
  4. Open the folder in the commandline
  5. Set your environment variables
    export AWS_AUTO_SCALING_HOME=/PATH/TO/AutoScaling-1.0.61.0/
    export JAVA_HOME=/PATH/TO/JAVA
    You can find java home by running which java in *nix
  6. ./as-create-launch-config ProdLaunchConfigV1 –image-id ami-123abc –instance-type m1.small –key YOUR_SECURITY_KEY –group YOUR_GROUP –I YOUR_KEY –S YOUR_SECRET
  7. ./as-create-auto-scaling-group ProdAutoScaleGroupV1 –launch-configuration ProdLaunchConfigV1 –availability-zones us-east-1b –min-size 1 –max-size 10 –load-balancers loadbalancer1 –I YOUR_KEY –S YOUR_SECRET

Side note: If you have to change the settings, you wont be able to delete the autoscaling group until all the instances are terminated, which is impossible unless you modify the autoscaling group with a minimum of 0 servers. Example:

  1. ./as-describe-launch-configs –I YOUR_KEY –S YOUR_SECRET
  2. ./as-describe-auto-scaling-groups –I YOUR_KEY –S YOUR_SECRET
  3. ./as-update-auto-scaling-group ProdAutoScaleGroupV1 –min-size 0 –max-size 0 ¬†–I YOUR_KEY –S YOUR_SECRET
  4. ./as-delete-auto-scaling-group ProdAutoScaleGroupV1 –I YOUR_KEY –S YOUR_SECRET
  5. ./as-delete-launch-config ProdLaunchConfigV1 –I YOUR_KEY –S YOUR_SECRET

Then terminate your instances and do what you need to do.

Leave a Reply

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