Getting Started with Auto Scaling
Whenever you plan to use Auto Scaling, you must use certain building blocks to get started. This tutorial walks you through the process for setting up the basic infrastructure for Auto Scaling.
The following step-by-step instructions help you create a template that defines your EC2 instances, create an Auto Scaling group to maintain the healthy number of instances at all times, and optionally delete this basic Auto Scaling infrastructure. This tutorial assumes that you are familiar with launching EC2 instances and have already created a key pair and a security group.
Step 1: Create a Launch Configuration
A launch configuration specifies the type of EC2 instance that Auto Scaling creates for you. You create the launch configuration by including information such as the Amazon Machine Image (AMI) ID to use for launching the EC2 instance, the instance type, key pairs, security groups, and block device mappings, among other configuration settings.
To create a launch configuration
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
On the navigation bar, select a region. The Auto Scaling resources that you create are tied to the region you specify and are not replicated across regions. For more information, see Example: Distributing Instances Across Availability Zones.
On the navigation pane, under Auto Scaling, choose Launch Configurations.
On the Welcome to Auto Scaling page, choose Create Auto Scaling group.
On the Create Auto Scaling Group page, choose Create launch configuration.
On the Choose AMI page, there is a list of basic configurations, called Amazon Machine Images (AMIs), that serve as templates for your instance. Select the 64-bit Amazon Linux AMI.
On the Choose Instance Type page, select a hardware configuration for your instance. We recommend that you keep the default, a
t2.microinstance. Choose Next: Configure details.
T2 instances must be launched into a subnet of a VPC. If you select a
t2.microinstance but don't have a VPC, one is created for you. This VPC includes a public subnet in each Availability Zone in the region.
On the Configure Details page, do the following:
For Name, type a name for your launch configuration (for example,
For Advanced Details, select an IP address type. If you want to connect to an instance in a VPC, you must select an option that assigns a public IP address. If you want to connect to your instance but aren't sure whether you have a default VPC, select Assign a public IP address to every instance.
Choose Skip to review.
On the Review page, choose Edit security groups. Follow the instructions to choose an existing security group, and then choose Review.
On the Review page, choose Create launch configuration.
On the Select an existing key pair or create a new key pair page, select one of the listed options. Note that you won't connect to your instance as part of this tutorial. Therefore, you can select Proceed without a key pair unless you intend to connect to your instance.
Choose Create launch configuration.
Step 2: Create an Auto Scaling Group
An Auto Scaling group is a collection of EC2 instances, and the core of the Auto Scaling service. You create an Auto Scaling group by specifying the launch configuration you want to use for launching the instances and the number of instances your group must maintain at all times. You also specify the Availability Zone in which you want the instances to be launched.
To create an Auto Scaling group
On the Configure Auto Scaling group details page, do the following:
For Group name, type a name for your Auto Scaling group (for example,
Keep Group size set to the default value of
1instance for this tutorial.
If you are launching a
t2.microinstance, you must select a VPC in Network. Otherwise, if your account supports EC2-Classic and you are launching a type of instance that doesn't require a VPC, you can select either
Launch into EC2-Classicor a VPC.
If you selected a VPC in the previous step, select one or more subnets from Subnet. If you selected EC2-Classic in the previous step, select one or more Availability Zones from Availability Zone(s).
Choose Next: Configure scaling policies.
On the Configure scaling policies page, select Keep this group at its initial size and choose Review.
On the Review page, choose Create Auto Scaling group.
On the Auto Scaling group creation status page, choose Close.
Step 3: Verify Your Auto Scaling Group
Now that you have created your Auto Scaling group, you are ready to verify that the group has launched an EC2 instance.
To verify that your Auto Scaling group has launched an EC2 instance
On the Auto Scaling Groups page, select the Auto Scaling group that you just created.
The Details tab provides information about the Auto Scaling group.
On the Activity History tab, the Status column shows the current status of your instance. While your instance is launching, the status column shows
In progress. The status changes to
Successfulafter the instance is launched. You can also use the refresh button to see the current status of your instance.
On the Instances tab, the Lifecycle column shows the state of your instance. You can see that your Auto Scaling group has launched your EC2 instance, and that it is in the
InServicelifecycle state. The Health Status column shows the result of the EC2 instance health check on your instance.
(Optional) If you want, you can try the following experiment to learn more about Auto Scaling. The minimum size for your Auto Scaling group is 1 instance. Therefore, if you terminate the running instance, Auto Scaling must launch a new instance to replace it.
On the Instances tab, select the ID of the instance. This shows you the instance on the Instances page.
Choose Actions, Instance State, Terminate. When prompted for confirmation, choose Yes, Terminate.
On the navigation pane, choose Auto Scaling Groups, Activity History. The default cooldown for the Auto Scaling group is 300 seconds (5 minutes), so it takes about 5 minutes until you see the scaling activity. When the scaling activity starts, you'll see an entry for the termination of the first instance and an entry for the launch of a new instance. The Instances tab shows the new instance only.
On the navigation pane, choose Instances. This page shows both the terminated instance and the running instance.
Go to the next step if you would like to delete your Auto Scaling set up. Otherwise, you can use this Auto Scaling infrastructure as your base and try one or more of the following:
Step 4: (Optional) Delete Your Auto Scaling Infrastructure
You can either delete your Auto Scaling set up or delete just your Auto Scaling group and keep your launch configuration to use at a later time.
To delete your Auto Scaling group
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
On the navigation pane, under Auto Scaling, choose Auto Scaling Groups.
Select your Auto Scaling group (for example,
Choose Actions, Delete. When prompted for confirmation, choose Yes, Delete.
The Name column indicates that the Auto Scaling group is being deleted. The Desired, Min, and Max columns shows
0instances for the Auto Scaling group.
Skip this procedure if you would like keep your launch configuration.