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
  4. Open the folder in the commandline
  5. Set your environment variables
    export AWS_AUTO_SCALING_HOME=/PATH/TO/AutoScaling-
    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.

Setting up a NATed VirtualBox FTP and Webserver with ProFTPD

A few quick steps to setting up a NATed VirtualBox FTP and Webserver for development. I’m going to assume you’re using some variant of linux.

  1. Install ProFTPD – for debian this would be apt-get install proftpd
  2. Add a user using the useradd command. Ex: useradd username -p password -d /apps -s /bin/false
  3. Edit the following lines in /etc/proftpd/proftpd.conf
    PassivePorts                  65532 65534 #Change the range as necessary, but keep it small
    RequireValidShell               off #If you disabled their shell using the command above make sure this is set to off, this is important for PASV
    MasqueradeAddress      #Or whatever address you have set for your guest IP, this is important for PASV
  4. Restart your ProFTPD server /etc/init.d/proftpd restart
  5. In VirtualBox go to Devices->Network Adapters and click on port forwarding and create the following rules:
    Name,Protocol,HostIP,Host Port,Guest IP,Guest Port

That’s it! You should be able to connect to the guest webserver and ftp server. Make sure you check PASV for your FTP client.