|« PreviousNext »|
|Did this page help you? Yes | No | Tell us about it...|
You can create an Auto Scaling group that launches Amazon EC2 instances into the Amazon Virtual Private Cloud (Amazon VPC).
Amazon VPC is a virtual network you can design that resembles a network running out of a data center. Amazon VPC enables you to create an isolated portion of the Amazon Web Services cloud where you can launch Amazon EC2 instances that have private addresses in the range of your choice. You can create a VPC that spans multiple Availability Zones. You can define subnets within your VPC that you can use to group similar kinds of instances based on IP address range. Each subnet must reside entirely within one Availability Zone. It is possible for you to define multiple subnets within an Availability zone, but Auto Scaling requires you to define one subnet per Availability Zone per Auto Scaling group.
When you launch your EC2 instances into a VPC, you have an option to
assign a public IP address to your instance. Assigning a public IP address to your instance
allows it to communicate with the Internet or other services in AWS. To assign a
public IP address to your instances, either use the
command option with the
as-create-launch-config command or the
AssociateIpAddress parameter with the CreateLaunchConfiguration
If your AWS account comes with a default virtual private cloud (default VPC), your Auto Scaling group is launched within the default VPC, by default, unless you specify a subnet from a nondefault VPC. For more information, see Detecting Your Supported Platforms and Whether You Have a Default VPC.
For information on launching your basic Auto Scaling infrastructure within EC2-Classic or the default VPC platforms, see Basic Auto Scaling Configuration.
In this section, we will walk you through the following steps for launching your basic Auto Scaling infrastructure within EC2-VPC platform:
Create an Amazon VPC.
Create subnets in your Amazon VPC.
Create a launch configuration.
Create Auto Scaling groups in your Amazon VPC subnets.
Check that instances are launched in the subnets we specified.
Delete your Auto Scaling group.
In this walkthrough exercise, when you create an Amazon VPC and subnets, you'll use Amazon EC2 command line tool commands, and we'll point you to documentation on how to use them. For the Auto Scaling tasks, you'll use the Auto Scaling CLI commands, which we'll discuss in more detail.
|Amazon EC2 CLI Commands||Description|
Creates a VPC with a CIDR block you specify.
Creates a subnet in an existing VPC.
Gives you information about your subnets.
Returns information about instances that you own.
|Auto Scaling CLI Commands||Description|
Creates a new launch configuration with specified attributes.
Creates a new Auto Scaling group with specified name and other attributes.
Describes the specified Auto Scaling group(s) if the group exists.
Describes a set of activities or all activities belonging to an Auto Scaling group.
Delete the specified Auto Scaling group if the group has no instances and no scaling activities in progress.
For common conventions the documentation uses to represent command symbols, see Document Conventions.
First, you need to create your Amazon Virtual Private Cloud (Amazon VPC) using the
ec2-create-vpc command. For information about
ec2-create-vpc in the Amazon Elastic Compute Cloud CLI Reference.
For information about Amazon VPC, see Introduction to the Amazon Virtual Private Cloud in the Amazon Virtual
Private Cloud User Guide.
In the following example you use the
ec2-create-vpc command to create a VPC.
The response includes your VPC ID.
VPC vpc-2e00c747 available 10.0.0.0/24 dopt-2200c74b default
You cannot create your subnet until you have created your Amazon VPC. Since you've just
created your Amazon VPC, you're ready to use the
ec2-create-subnet command to
create a subnet; specify the VPC ID from the previous step.
ec2-create-subnet --vpc vpc-2e00c747 -cidr "10.0.0.0/28" --availability-zone us-east-1a
For information about
ec2-create-subnet, see ec2-create-subnet
in the Amazon Elastic Compute Cloud CLI Reference.
The subnet will be created in your VPC in the Availability Zone you specified.
SUBNET subnet-530fc83a available vpc-2e00c747 10.0.0.0/28 11 us-east-1a us-east-1
Create a subnet in a different Availability Zone.
ec2-create-subnet --vpc vpc-2e00c747 -cidr "10.0.0.128/28" --availability-zone us-east-1b
The subnet will be created in your VPC in the Availability Zone you specified.
SUBNET subnet-610acd08 available vpc-2e00c747 10.0.0.128/28 11 us-east-1a
Get a list of subnets in your VPC.
You will get information about the two subnets you just created in your VPC.
SUBNET subnet-610acd08 available vpc-2e00c747 10.0.0.128/28 11 us-east-1b us-east-1 SUBNET subnet-530fc83a available vpc-2e00c747 10.0.0.0/28 11 us-east-1a us-east-1
After you've created your Amazon VPC and subnets, you define the Auto Scaling scenario. Create a launch configuration, or use an existing launch configuration.
The Auto Scaling launch configuration specifies the template that Auto Scaling uses to launch Amazon EC2 instances. This template contains all the information necessary for Auto Scaling to launch instances that run your application. If you've never created a launch configuration before, see Create a Launch Configuration.
Specify the following values for the required options:
Launch configuration name:
The AMI ID is provided for illustration purposes only. AMI IDs change over time. You can
obtain current, valid AMI IDs by calling the
In addition, specify the
--region general option:
The AMI or image ID you specify must be supported in the region of your Amazon VPC.
as-create-launch-config command will look like this:
as-create-launch-config myvpclc --image-id ami-b4b0cae6 --instance-type m1.small
You will get a confirmation that your launch configuration was created successfully.
OK-Created launch config
An Auto Scaling group is a collection of Amazon EC2 instances. You can specify settings like the minimum, maximum, and desired number of EC2 instances for an Auto Scaling group to which you want to apply certain scaling actions. For information about how to create an Auto Scaling group, see Create an Auto Scaling Group.
Specify these values for the following options:
Auto Scaling group name:
Launch configuration name:
To launch instances in the subnets you created in your Amazon VPC, you also must specify the following zone identifier and region:
VPC zone identifier:
Do NOT use the VPC identifier to specify the VPCZoneIdentifier parameter. Amazon VPC has both a VPC identifier (e.g., vpc-1a2b3c4d) and a subnet identifier (e.g., subnet-9d4a7b6c). You must use the subnet identifier instead of the VPC identifier.
The Availability Zone of the subnet must match the Availability Zone you specify. In addition, when you specify several subnets and Availability Zones separated by commas (,) make sure that there is no space between the comma and the next item.
Your request will look like this:
as-create-auto-scaling-group myvpcasgroup --launch-configuration myvpclc --availability-zones "us-east-1b,us-east-1a" --min-size 0 --max-size 10 --desired-capacity 10 --vpc-zone-identifier "subnet-610acd08,subnet-530fc83a"
The response should look something like this.
To verify that your Auto Scaling group successfully launched instances in the Availability Zone you specified in your Amazon VPC subnets, you can use the following commands:
as-describe-auto-scaling-groups command describes the Auto Scaling
group, if it exists. Run this command to confirm that the Auto Scaling group
myvpcasgroup was created and is launching instances according to your
as-describe-auto-scaling-groups myvpcasgroup -H
Our example response confirms that the Auto Scaling group
was created and that instances were launched according to specifications.
AUTO-SCALING-GROUP GROUP-NAME LAUNCH-CONFIG AVAILABILITY-ZONES MIN-SIZE MAX-SIZE DESIRED-CAPACITY AUTO-SCALING-GROUP myvpcasgroup myvpclc us-east-1b,us-east-1a 0 10 10 INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIG INSTANCE i-e5f4c3b0 us-east-1b InService Healthy myvpclc INSTANCE i-e7f4c3b2 us-east-1b InService Healthy myvpclc INSTANCE i-eff4c3ba us-east-1b InService Healthy myvpclc INSTANCE i-e9f4c3bc us-east-1b InService Healthy myvpclc INSTANCE i-ebf4c3be us-east-1b InService Healthy myvpclc INSTANCE i-95f4c3c0 us-east-1a InService Healthy myvpclc INSTANCE i-97f4c3c2 us-east-1a InService Healthy myvpclc INSTANCE i-9df4c3c8 us-east-1a InService Healthy myvpclc INSTANCE i-93f4c3c6 us-east-1a InService Healthy myvpclc INSTANCE i-91f4c3c4 us-east-1a InService Healthy myvpclc
as-describe-scaling-activities command lists the scaling activities for the Auto Scaling group.
When you run this command, it lists the activities that took place for the
as-describe-scaling-activities --auto-scaling-group myvpcasgroup -H
The response shows 10 activities that were successfully run within the timespan of a minute for Auto Scaling group
ACTIVITY ACTIVITY-ID END-TIME GROUP-NAME CODE ACTIVITY 188b5c5f-79fc-4dcc-95a3-2762eba64702 2011-12-12T22:46:08Z myvpcasgroup Successful ACTIVITY bc35c15e-cfb1-491c-b4e5-4bc99bf1f68c 2011-12-12T22:46:24Z myvpcasgroup Successful ACTIVITY b30546fb-b4a7-47fb-bb20-3e8f977bfbdd 2011-12-12T22:46:20Z myvpcasgroup Successful ACTIVITY 18be6da1-7448-4548-97f7-fe1d6a86538a 2011-12-12T22:46:19Z myvpcasgroup Successful ACTIVITY 7952cf76-b3d2-4faf-b725-137d79bb5769 2011-12-12T22:46:21Z myvpcasgroup Successful ACTIVITY ad501827-5b10-4479-aadf-6b6ef6eb22bc 2011-12-12T22:46:19Z myvpcasgroup Successful ACTIVITY 90cad1e5-c64a-44b9-a619-25440fa411ad 2011-12-12T22:46:08Z myvpcasgroup Successful ACTIVITY 3acc0e73-17fa-4326-9a16-11ec65295456 2011-12-12T22:46:38Z myvpcasgroup Successful ACTIVITY 6865beb5-98da-4377-a684-b727be1cc686 2011-12-12T22:46:38Z myvpcasgroup Successful ACTIVITY cf072f5a-021b-4c1a-8557-827e19af3a76 2011-12-12T22:46:19Z myvpcasgroup Successful
ec2-describe-instances command describes instances that were launched. In this walkthrough you run the command, specifying
the instance ID of one of the 10 instances launched by the
myvpcasgroup, with the verbose flag general
--verbose) to see if the private IP address of the instance is in the
ec2-describe-instances i-e5f4c3b0 --verbose
Here is part of the response.
RESERVATION r-ad623af8 629715795501 INSTANCE i-e5f4c3b0 ami-b4b0cae6 running 0 m1.small 2011-12-12T22:45:32+0000 us-east-1b aki-a4225af6 monitoring-enabled 10.0.0.136 vpc-2e00c747 subnet-610acd08 ebs paravirtual xen cf072f5a-021b-4c1a-8557-827e19af3a76 sg-a19f8ccd default BLOCKDEVICE /dev/sda1 vol-2eeea540 2011-12-12T22:46:08.000Z TAG instance i-e5f4c3b0 aws:autoscaling:groupName myvpcasgroup REQUEST ID 30e8d688-652f-4a1b-b772-ede8e4a4e72c
After you're done using your instances and Auto Scaling group, it is good practice to clean up. An efficient way to perform this task is
by running the
as-delete-auto-scaling-group command with the optional
--force-delete parameter. Force delete
specifies that instances of the Auto Scaling group will be deleted together with the Auto Scaling group even if the instances are still running.
If you don't specify
--force-delete parameter when you cannot delete your Auto Scaling group until you've manually stopped and terminated
all instances of that Auto Scaling group.
Run the command with the following values:
Auto Scaling group name:
Force delete (optional parameter):
This is how your command will look.
as-delete-auto-scaling-group myvpcasgroup --force-delete
Confirm that you want to delete the Auto Scaling group and it will be deleted.
Are you sure you want to delete this AutoScalingGroup? [Ny] OK-Deleted AutoScalingGroup
You just performed the following tasks:
Created an Amazon VPC.
Created two subnets in the Amazon VPC.
Created a launch configuration.
Created an Auto Scaling group.
Confirmed that your Auto Scaling group exists.
Checked that your Auto Scaling group contains running instances in the subnet you created.
Deleted your Auto Scaling group.
Following is the complete snippet used to perform these tasks. You can copy the snippet, replace the values with your own, and use the code to get started.
ec2-create-vpc "10.0.0.0/24" ec2-create-subnet --vpc vpc-2e00c747 -cidr "10.0.0.0/28" --availability-zone us-east-1a ec2-create-subnet --vpc vpc-2e00c747 -cidr "10.0.0.128/28" --availability-zone us-east-1b as-create-launch-config myvpclc --image-id ami-b4b0cae6 --instance-type m1.small as-create-auto-scaling-group myvpcasgroup --launch-configuration myvpclc --availability-zones "us-east-1b,us-east-1a" --min-size 0 --max-size 10 --desired-capacity 10 --vpc-zone-identifier "subnet-610acd08,subnet-530fc83a" as-describe-auto-scaling-groups myvpcasgroup -H as-describe-scaling-activities --auto-scaling-group myvpcasgroup -H ec2-describe-instances i-e5f4c3b0 --verbose as-delete-auto-scaling-group myvpcasgroup --force-delete