The following is a guide on how to set up AWS Auto Scaling for your Amazon EC2 servers. The guide shows the manual steps using the command line tools.



Steps for using the Amazon Command Line Tools:


Pre-requisites


Knowing your region
The region where your EC2 instances will be created can be viewed in the top-right corner of your AWS Management Console.

Know your AWS Region

Having an AMI
Under the Services tab select EC2 and then click on AMIs in the left panel. In the right panel you need to have an AMI. If you don't have one then you need to create one. Every new Auto Scaling EC2 instance that is created will be an exact copy of this AMI.

Know your AMIs

Know your AMIs

Having a load balancer
Similarly to AMIs, the left panel has a link for Load Balancers. You need to create at least 1 load balancer. Every new Auto Scaling EC2 instance will be added to this load balancer. When you first create the load balancer, you don't need to attach any instances to it.

AWS Load Balancers

FYI: All of the steps below are converted to a web-based interface in EZAutoScaling's online tool. If you use EZAutoScaling you will not need to execute any of the steps below.

Download the command line tools for Auto Scaling


This is probably one of the easier steps in this guide. Click on this link and download the command line tools for Auto Scaling.

Download Auto Scaling command line tools

Download the command line tools for CloudWatch


Similarly to the step above, click on this link and download the command line tools for CloudWatch.

Download CloudWatch command line tools

Set up Auto Scaling command line


After you unzip the command line tools to a directory, go that that directory. Setting up the command line is described in the file README.TXT.
There are quite a few pre-requisites to make this work, but the assumption for this guide is that you have the JAVA pre-requisites; you just need to set up the security keys to get the command line to work.

Here are the steps as per the README file:
1. Ensure that JAVA version 1.5 or higher is installed on your system: (java -version) [Assumption is that this is set up]
2. Unzip the deployment zip file [Assumption is that this is done]
3. Set the following environment variables:
3.1 AWS_AUTO_SCALING_HOME - The directory where the deployment files were copied to. 3.2 JAVA_HOME - Java Installation home directory [Assumption is that this is set up]
4. Add "%AWS_AUTO_SCALING_HOME%\bin" to your path (Windows)

Configuration of security keys; this guide will demonstrate how to set up the AWS keys with a credentials file:
1. Create your credentials file 2. Set up the environment variable to the credentials file
3. Finally, to check you have set up everything properly:

Set up CloudWatch command line


Setting this up is extremely similar to setting up Auto Scaling.

After you unzip the command line tools to a directory, go that that directory. Setting up the command line is described in the file README.TXT.
There are quite a few pre-requisites to make this work, but the assumption for this guide is that you have the JAVA pre-requisites; you just need to set up the security keys to get the command line to work.

Here are the steps as per the README file:
1. Ensure that JAVA version 1.5 or higher is installed on your system: (java -version) [Assumption is that this is set up]
2. Unzip the deployment zip file [Assumption is that this is done]
3. Set the following environment variables:
3.1 AWS_CLOUDWATCH_HOME - The directory where the deployment files were copied to. 3.2 JAVA_HOME - Java Installation home directory [Assumption is that this is set up]
4. Add "%AWS_CLOUDWATCH_HOME%\bin" to your path (Windows)

Configuration of security keys; this guide will demonstrate how to set up the AWS keys with a credentials file:
1. Create your credentials file

2. Set up the environment variable to the credentials file:
3. Finally, to check you have set up everything properly:

Create new Launch Configuration


The first step in creating an Auto Scaling group is to create a launch configuration for each new instance in the Auto Scaling Group.
To create a launch configuration:
Create AWS Launch Configuration

The command can get much more detailed than the above, however as a start the above is sufficient.

Create new Auto Scaling Group


The auto scaling group says which launch configuration to use, what region, and which load balancer.
To create an auto scaling group:
Create AWS Auto Scaling Group


The command can get much more detailed than the above, however as a start the above is sufficient. After the above command runs, wait a few seconds and you should see new EC2 instances being created in your AWS Management Console. In the screenshot above the desired starting capacity was 1, therefore 1 new EC2 instance should start getting created.

Create AWS Auto Scaling Group

Also make sure when you set this up that you test it - you need to make sure that each EC2 instance that is added to the Load Balancer is added and becomes "InService" in the load balancer. If it is "OutOfService" in the load balancer then the Health Check that the load balancer does is failing. This means that no requests will be routed to that EC2 instance.

Create per region


Auto Scaling is region specific. Below is a screenshot of regions in which you can create EC2 instances, and consequently independent Auto Scaling Groups:

AWS Regions

Therefore, if you want to have EC2 instances in 2 different regions, you need to create an Auto Scaling Group for each region (i.e. 2 Auto Scaling Groups).

To create Auto Scaling groups in different regions you need to add an extra parameter to the commands that you write. Every single command needs to have --region Region API Name, for example --region us-west-1.

The Launch Configuration creation command would be:
as-create-launch-config lc1 --image-id ami-12345678 --instance-type c1.xlarge --key securitykey1 --region us-west-1
The Auto Scaling Group creation command would be:
as-create-auto-scaling-group as-group1 --launch-configuration lc1 --availability-zones us-east-1a --min-size 1 --max-size 50 --desired-capacity 1 --load-balancers lb1 LoadBalancer --region us-west-1

Create CloudWatch monitor to increase servers


The next important steps is to add a CloudWatch monitor so that if something occurs (such as CPU usage is too high on an EC2 instance) then a new EC2 instance will spawn in an Auto Scaling Group automatically.
Thanks to CardinalPath for the easy examples.

The steps are:

Create CloudWatch monitor to decrease servers


In the previous step you set up EC2 instances to automatically get created. This step sets up CloudWatch monitors to terminate EC2 instances in an Auto Scaling group.
Thanks to CardinalPath for the easy examples.

The steps are:

Set Desired Capacity after creation


There are many commands in the Auto Scaling command line tool package that allow you to edit an Auto Scaling Group. One most common usage is editing the number of EC2 instances that should be live currently. This is called "setting the desired capacity". To change the desired capacity do the following:
AWS Auto Scaling Set Desired Capacity

You should see the changes take effect a few seconds later. With the above command my auto scaling group had 1 instance and the command just added a 2nd.

AWS Auto Scaling Set Desired Capacity

Monitoring your Auto Scaling Groups


There are a few ways to see how the Auto Scaling groups are doing in terms of health and status. The easiest is the following command: This command will list all your Auto Scaling Groups for your default region (or you can specify the region parameter for another region), with headers, and it will also list all of the instances in that Auto Scaling Group.

AWS Auto Scaling Describe Groups

Monitoring your Instances' health


There is no command line method to map Auto Scaling Groups and their instances to health information (such as CPU%) about the instances. You will need to remember or find out which EC2 instances make up your Auto Scaling Group and then check the health either through the AWS Management Console or using CloudWatch Command Line tools for those particular instances.

For example, you will need to find each EC2 instance that makes up your Auto Scaling Group and then use AWS Management Console to check up on its health as in the screenshot below:

AWS Monitor Auto Scaling and EC2 Instances or use CloudWatch

On a side note, this is an area where EZAutoScaling is useful because it adds this mapping of EC2 Instances to Auto Scaling Groups and provides EC2 health information on one screen.

Delete Auto Scaling Groups and Launch Configurations


Deleting an Auto Scaling Group means first deleting the group (which terminates the EC2 instances of that group) and then deleting the Launch Configuration. If you have CloudWatch monitors attached, you can delete those separately through the AWS Management Console - they will simply stop monitoring and alerting. The steps to delete are:
AWS Auto Scaling Delete Auto Scaling Group and Launch Configuration

You should soon see the EC2 instances being terminated.

AWS Delete Auto Scaling Group terminates EC2 instances

Summary

Let's quickly summarize the steps and commands needed to auto scale:
Or, don't bother with all of these commands and instead sign up for EZAutoScaling.

Sign Up

Back to How To Guides


Back to top

Copyright © EZAutoScaling Inc. About · Contact · Privacy · Terms

"Amazon Web Services", "AWS", "Auto Scaling", "EC2", "CloudWatch" are trademarks of Amazon.com, Inc.