This article is the first part of a series discussing Auto Scaling service in AWS.

Auto Scaling is an AWS service that allows you to increase or decrease the number of EC2 instances based on your application needs. You can also configure Auto Scaling to maintain a fixed number of EC2 instances in the situation that one EC2 instance fails for whatever reason.

VMware Training – Resources (Intense)

This first part will discuss the following:

  • Basic notions about Auto Scaling
  • Auto Scaling group configuration with fixed number of EC2 instances
  • Auto Scaling group dynamic resource allocation

The benefits of Auto Scaling are:

  • Fault tolerant – in case one EC2 instance is unhealthy, Auto Scaling will terminate it and launch another one to replace it
  • High availability – you can launch EC2 instances in different Availability Zones
  • Dynamic allocation of resources – you can launch new EC2 instances only when you need them and terminate them when you no longer need them and pay only when you use them

There are three fundamental notions regarding Auto Scaling:

  • Launch Configuration – this is a template that is being used by Auto Scaling to launch EC2 instances. Launch configuration templates contain information about AMI to be used: instance type, security keys, block devices and a few other settings. The launch configuration is associated with an Auto Scaling group. The launch configuration cannot be changed after it is created. In case you would like to change the launch configuration of an Auto Scaling group, you need to create a new launch configuration and associate the new one with the Auto Scaling group.
  • Auto Scaling group – is a representation of multiple EC2 instances that have the same characteristics. All EC2 instances are treated as a single logical device.
  • Scaling Plans – these are ways to configure the Auto Scaling groups. So you can maintain the current levels of instances, you can manually scale or scale on a schedule or on demand.

The first step to use Auto Scaling is to create a launch configuration. You are doing this from an EC2 console by clicking on “Launch Configurations” from “AUTO SCALING” menu. Click on “Creating Auto Scaling Group” to start the process. First you will create the launch configuration and then the auto scaling group:

Select your preferred AMI that you would like to use:

Select the instance type:

Next, you will need to specify a name for the launch configuration and then leave everything else as it is and continue:

Add the storage to your AMI and continue:

Add the security group with your rules:

Next, you can review the launch configuration:

Once you click on “Create launch configuration”, you will be prompted that you need a key pair to access your instances. Use one already created or choose to create one. Also you can proceed by not using any, but in this case you will not be able to connect to the instances.

Once you do this, you will be redirected to the auto scaling group configuration.

The first step will ask you for few things:

  • Group name – this is self explanatory
  • Group size – this is how many instances the group should have
  • Network – specify if you want to launch the group in a VPC to have more control of the network settings
  • Subnet – specify that you want to isolate the EC2 instances among them, like creating them in different Availability Zones

I choose two other subnets/AZ: us-east-1b, us-east-1d.

Click on “Next: Configure scaling policies” to go to the next step:

On this step you can specify if your scaling group can dynamically adjust its size based on the Cloudwatch alarms. Or you can keep the scaling group at the same size all the time.

Keep this group at its initial size – the group will always have the same number of healthy EC2 instances. In case one EC2 instances fails, another one will be created.

Use scaling policies to adjust the capacity of this group – the policy will allow increasing the group or decreasing it based on Cloudwatch alarms.

For now, we will go with the first option.

Click on “Next: Configure Notifications” after selecting the first option:

On the next step, you can setup notifications to be sent in case an EC2 instance terminates, launches or fail to launch or terminate.

In this case, I selected that I want to receive an email whenever this is happening. Then click on “Next: Configure Tags” to go to the next step:

On this step, you can tag all your EC2 instances to know which one is part of the auto scaling group. Once you are done, you can click on “Review”:

On this step, you can review the settings of the auto scaling group and you proceed to create it by clicking on “Create Auto Scaling group”:

You can check the auto scaling group by choosing “Auto Scaling Groups” from the EC2 Console:

As you can see, I have three instances running and they will be redistributed in two AZ.

You can check the EC2 instances created like you would check any other EC2 instances. Go to “Instances” menu from EC2 console. As you can see, the three EC2 instances have been tagged as we specified in one of the steps of auto scaling group configuration:

Remember that we created notifications to be sent when, for instance, an EC2 instance is launched. We launched three EC2 instances and we should have received three emails, which I did. This is one of them:

Let’s test that if I terminate one EC2 instance, then another one will be launched.

So, I terminated one and you should see something similar to:

You can check the scaling history by choosing the auto scaling group from the “Auto Scaling Groups” and then choosing the “Scaling History” tab:

And we reached the end of our first part tutorial regarding auto scaling.

By now, you should know what AWS Auto Scaling is and how you can make use of it.

In this article we used a scaling plan that allowed us to maintain current instance levels at all times. Also, we saw how we can get notified in case a new EC2 instance is launched or terminated.

The next part will discuss scaling policies and load balancing for auto scaling groups.