Auto-Scaling with EC2
Set up a scalable server farm in less than 10 minutes with Amazon Elastic Compute Cloud utilizing Elastic Load Balancing and Auto Scaling.
Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable compute capacity in the cloud. It is designed to make web-scale computing easier for developers.
If you have used EC2 at all you must have wondered how you can automate the creation of instances in your load balancer. So did we. After much searching and various testing back and forth we came up with the following solution.
The EC2 tools all require Java to be installed. Follow the instructions for your operating system in order to install a Java runtime environment.
First you need to install these tools from Amazon:
To make these exercises easier for you to read we have selected Ubuntu as our operating system. If you have a Mac there are very few things you need to change apart from how to install the above mentioned command line tools.
The EC2 command line tools are available through the Ubuntu Multiverse repository which you can activate through your package manager. Once you have done this, run the following command to install the tools:
$ sudo apt-get install ec2-api-tools
Once you have installed the tools you need to download your key pair from Amazon so that you can access the API via the tools. In order to do this you need to access them through your AWS Account. Once there, click the “Security Credentials” link, here you need to create an X.509 Certificate for use with the EC2 Tools.
|![X.509 Certificates - Create Certificate](‘/assets/uploads/2011/03/createcert.png’||relative_url)|
Download both the Private Key File and the X.509 Certificate by using the two buttons.
|![Download X.509 Certificate](‘/assets/uploads/2011/03/x.509cert.png’||relative_url)|
Store your private key file somewhere safe. Like the text above states, if you lose it, there is no way to recover and you will have to create a new certificate. This is especially important with your SSH key used with your instances since you will lose SSH access if you lose your private key part.
Once you have both certificate parts, create the following directory:
In this directory create sub directories for
AutoScaling. Extract the respective tools into these directories and create the following files:
We are simply being lazy above and making sure that all executable files are executable and that the
*.cmd files are not.
Now we can create the actual script that sets up our auto-scaling load balancer!
With the above script you will have a load balancer set up to scale between 2 and 6 instances. Feel free to tweak the values here to ensure that it works best for you.