| « PreviousNext » | |
![]() ![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
You can use Auto Scaling group tags to organize your Auto Scaling resources and provide additional information for your Auto Scaling group such as software version, role, or location information. Like Amazon Elastic Compute Cloud (Amazon EC2) tags, Auto Scaling group tags provide search, group, and filter functionality. These tags have a key and value that can be modified. You can also remove Auto Scaling group tags any time. For more information about Amazon EC2 tags, see Using Tags.
Additional Features
Optionally, you can propagate Auto Scaling group tags to the Amazon EC2 instances launched by Auto Scaling. The Auto Scaling group tags that you propagate to Amazon EC2 instances can be used like any other Amazon EC2 instance tag, including cost allocation. For more information about cost allocation, see Cost Allocation and Tagging in the AWS Account Billing.
When you use the PropagateAtLaunch flag with the as-create-or-update-tags
command, the tag you create will be applied to new Amazon EC2 instances launched by the Auto
Scaling group. Likewise, when you modify a tag, the updated version will be applied to new
instances launched by the Auto Scaling group after the change. Tags created or modified with the
as-create-or-update-tags command will not apply to instances that are already
running at the time you used the command. For an example, go to Change the Tag.
Note
When you launch instances in an Auto Scaling group, Auto Scaling automatically tags each one with the group name.
This tag can be identified by its key, aws:autoscaling:groupName. Tags containing the prefix aws:
have been created by AWS, cannot be edited or deleted, and do not count against your limit of 10 tags per instance.
In this section, we will use the Auto Scaling command line interface (CLI) commands to create and update tags. We will use Amazon EC2 CLI commands to confirm that the new and updated tags are applied to instances launched after the tags are created. In this scenario, we will perform the following tasks:
Create a launch configuration.
Create an Auto Scaling group with a tag.
Confirm that the Auto Scaling group has a tag and that the tag is applied to instances that the Auto Scaling group launches.
Change the tag and the Auto Scaling group, and confirm that the changes are propagated to the new instances that the Auto Scaling group launches.
Clean up.
You will use the following Auto Scaling and Amazon EC2 command line interface (CLI) commands.
Note
We will discuss in detail the Auto Scaling CLI commands. For more information on specific Amazon EC2 CLI commands that we use in this walkthrough, go to the Amazon Elastic Compute Cloud CLI Reference.
| Command | Description |
|---|---|
|
|
Creates a new launch configuration with specified attributes. |
|
|
Creates a new Auto Scaling group with specified name and other attributes. |
|
|
Creates new tags or updates existing tags. |
|
|
Describes the Auto Scaling groups, if the groups exist. |
|
|
Describes the Auto Scaling instances, if the instances exist. |
|
|
Lists your tags. You can filter the list to return only the tags you specify. |
|
|
Updates specified Auto Scaling group. |
|
Returns information about EC2 instances that you own. | |
|
|
Deletes the specified auto scaling group, if the group has no instances and no scaling activities are in progress. |
For common conventions the documentation uses to represent command symbols, see Document Conventions.
If you're not familiar with how to create a launch configuration or an Auto Scaling group, we recommend that you go through the steps in the Basic Auto Scaling Configuration. Use the basic scenario to get started with the infrastructure that you need in most Auto Scaling scenarios.
For this tagging walkthrough, the following values will be specified for the as-create-launch-config
command:
Launch configuration name = MyTagLC
Image ID = ami-31814f58
If you don't have an AMI, and you want to find a suitable one, see Amazon Machine Images (AMIs).
Instance type = m1.small
Your command should look similar to the following example:
as-create-launch-config MyTagLC --image-id ami-31814f58 --instance-type m1.small
You should get a confirmation like the following example:
OK-Created launch config
Create your Auto Scaling group with a tag and specify that the tag also applies to the instances launched by the Auto Scaling group.
You use the --tag option to define the tag for your Auto Scaling group and instances. For more detailed information on the syntax of
the as-create-auto-scaling-group command, go to Create an Auto Scaling Group.
Specify these values for the command:
Auto Scaling Group name = MyTagASG
Launch configuration name = MyTagLC
Availability Zone = us-east-1a
Max size = 10
Min size = 1
In addition, the --tag parameter should be specified this way:
--tag "k=value, [id=value],
[t=value], [v=value], [p=value]" [--tag "k=value, [id=value],
[t=value], [v=value], [p=value]"...]
Provide these values for the following tag options:
| Option | Description | Example value |
|---|---|---|
|
|
Tag's key, as part of key-value pair. Always required. | version |
|
|
Tag's value, as part of key-value pair. Optional. | 1.0 |
|
|
The type of resource to which the tag is applied. Not required with | Not specified with the as-create-auto-scaling-group command. |
|
|
The name of the resource to which the tag is applied. Not required with | Not specified with the as-create-auto-scaling-group command. |
|
|
The propagate-at-launch flag. Specify this flag only if you want the tags to be applied to newly launched Amazon EC2. | true |
Your command should look like the following example:
as-create-auto-scaling-group MyTagASG --launch-configuration MyTagLC --availability-zones us-east-1a --min-size 1 --max-size 10 --tag "k=version, v=1.0, p=true"
You should get confirmation like the following example:
OK-Created AutoScalingGroup
To verify that the tag is created, applied to the Auto Scaling group, and that the instance is launched, use the following Auto Scaling commands:
as-describe-tags
as-describe-auto-scaling-groups
as-describe-auto-scaling-instances
In addition, use the ec2-describe-instances EC2 command to get detailed
information about the instances that the Auto Scaling group launched.
Use the as-describe-tags command to verify that the tag is created. The command takes the following arguments:
as-describe-tags
[
--filter "key1=value1,key2=value2..."
[--filter "key1=value1,key2=value2..." ...]] [General Options]
The key1, key2 filter options are the resource name, resource type, tag key, tag value, and the propagate flag that you used to define your tag.
For this walkthrough, specify the following:
Tag key: key=version
Tag value: value=1.0
Your command should look like the following example:
as-describe-tags --filter "key=version, value=1.0"
You should receive a confirmation that Auto Scaling created the tag, like the following example response:
TAG MyTagASG auto-scaling-group version 1.0 true
Use the as-describe-auto-scaling-groups command to confirm that the tag is applied to the Auto Scaling group MyTagASG.
The command describes the Auto Scaling group, if the group exists, and takes the following arguments:
as-describe-auto-scaling-groups
[
AutoScalingGroupNames[AutoScalingGroupNames...]][--max-records value] [General Options]
Your command should look like the following example:
as-describe-auto-scaling-groups MyTagASG
You should receive a response that includes information confirming that Auto Scaling applied
the tag to the Auto Scaling group MyTagASG. The response should look like the following example:
AUTO-SCALING-GROUP MyTagASG MyTagLC us-east-1a 1 10 5
INSTANCE INSTANCE-ID AVAILABILITY-ZONE STATE STATUS LAUNCH-CONFIG
TAG RESOURCE-ID RESOURCE-TYPE KEY VALUE PROPAGATE-AT-LAUNCH
TAG MyTagASG auto-scaling-group version 1.0 true
Use the as-describe-auto-scaling-instances command to get a list of EC2 instance that the Auto Scaling group launched.
This command describes the specified Auto Scaling instances, if they exist, or lists all the Auto Scaling instances if no instance is specified.
The command takes the following arguments:
as-describe-auto-scaling-instances
[
InstanceIds[InstanceIds...]][--max-records value] [General Options]
For this walkthrough, do not specify any of the optional parameters, so your command should look like the following example:
as-describe-auto-scaling-instances
You should get a listing that looks like the following example:
INSTANCE i-33698556 MyTagASG us-east-1b InService Healthy MyTagLC
From the result, get the instance ID of the instance that the MyTagASG launched. You will use it for the next command.
Use the ec2-describe-instances command to get specific information about EC2 instances. This command returns information
about instances you own. For more information about this CLI command, see
ec2-describe-instances.
In the ec2-describe-instances command, specify the instance ID of the EC2 instance to which the tag was propagated.
Your command should look like the following example:
ec2-describe-instances i-33698556Your result should show that the tag was applied to the instance, as in the following example:
RESERVATION r-45253524 629715795501 default
INSTANCE i-33698556 ami-31814f58 ec2-23-20-37-36.compute-1.amazonaws.com ip-10-32-153-166.ec2.internal running 0 m1.small 2012-01-23T21:41:44+0000 us-east-1a aki-805ea7e9 monitoring-enabled 23.20.37.36 10.32.153.166 ebs paravirtual xen 29849241-1242-4524-ba07-09248cd29652 sg-286ee441 default
BLOCKDEVICE /dev/sda1 vol-2f303942 2012-01-23T21:42:12.000Z
TAG instance i-33698556 version 1.0
TAG instance i-33698556 aws:autoscaling:groupName MyTagASG
Now you can update the tag and modify the Auto Scaling group. Use the
as-create-or-update-tags command and the as-update-auto-scaling-group command to make the changes.
The as-create-or-update-tags command takes the following arguments:
as-create-or-update-tags
--tag "id=value,t=value,
k=value, [v=value],
[p=value]" [--tag "id=value,
t=value, k=value,
[v=value], [p=value]]" ...] [General Options]
Update the tag value to 2.0, so your command should look like the following example:
as-create-or-update-tags --tag "id=MyTagASG, t=auto-scaling-group, k=version, v=2.0, p=true"
Note
You must specify the resource name and resource type so that Auto Scaling knows to which Auto Scaling resource the tag applies.
Resource name is the id (in the example it's id=MyTagASG) and resource type is t
(in the example, it's t=auto-scaling-group).
You should receive a confirmation similar to the following example:
OK-Created/Updated tags
Now, you can use the as-update-auto-scaling-group command to modify the Auto Scaling group by increasing the number of EC2 instances
to be launched. Change the min-size value to 5.
The as-update-auto-scaling-group command takes the following arguments:
as-update-auto-scaling-group
AutoScalingGroupName [--availability-zones value[,value...]]
[--default-cooldown value] [--desired-capacity value]
[--grace-period value] [--health-check-type value]
[--launch-configuration value] [--max-size value]
[--min-size value] [--placement-group value]
[--vpc-zone-identifier value] [General Options]
Your command should look similar to the following example:
as-update-auto-scaling-group MyTagASG --min-size 5
The confirmation should look like the following example:
OK-Updated AutoScalingGroup
To verify that Auto Scaling updated the Auto Scaling Group MyTagASG and that Auto Scaling launched four
additional instances to meet the new minimum size of 5, run the as-describe-auto-scaling-instances command with no arguments, like the following example:
as-describe-auto-scaling-instances
Your results should be similar to the following example:
INSTANCE i-2346af46 MyTagASG us-east-1a InService HEALTHY MyTagLC INSTANCE i-2546af40 MyTagASG us-east-1a InService HEALTHY MyTagLC INSTANCE i-33698556 MyTagASG us-east-1a InService HEALTHY MyTagLC INSTANCE i-5346af36 MyTagASG us-east-1a InService HEALTHY MyTagLC INSTANCE i-566da836 MyAutoScalingGroup us-east-1b InService HEALTHY MyLCwebapp INSTANCE i-5946af3c MyTagASG us-east-1a InService HEALTHY MyTagLC
To verify that tag value 2.0 was applied to instances launched after the tag was updated, run the ec2-describe-instances command.
You should get a result set similar to the following example:
RESERVATION r-45253524 629715795501 default INSTANCE i-33698556 ami-31814f58 ec2-23-20-37-36.compute-1.amazonaws.com ip-10-32-153-166.ec2.internal running 0 m1.small 2012-01-23T21:41:44+0000 us-east-1a aki-805ea7e9 monitoring-enabled 23.20.37.36 10.32.153.166 ebs paravirtual xen 29849241-1242-4524-ba07-09248cd29652 sg-286ee441 default BLOCKDEVICE /dev/sda1 vol-2f303942 2012-01-23T21:42:12.000Z TAG instance i-33698556 version 1.0 TAG instance i-33698556 aws:autoscaling:groupName MyTagASG RESERVATION r-b1ebf9d0 629715795501 default INSTANCE i-5346af36 ami-31814f58 ec2-107-22-159-5.compute-1.amazonaws.com ip-10-204-54-176.ec2.internal running 0 m1.small 2012-01-24T07:17:50+0000 us-east-1a aki-805ea7e9 monitoring-enabled 107.22.159.5 10.204.54.176 ebs paravirtual xen a848fb19-703f-4579-9ee4-930b2f1e5a9f sg-286ee441 default BLOCKDEVICE /dev/sda1 vol-b3aea6de 2012-01-24T07:18:10.000Z TAG instance i-5346af36 aws:autoscaling:groupName MyTagASG TAG instance i-5346af36 version2.0RESERVATION r-b7ebf9d6 629715795501 default INSTANCE i-5946af3c ami-31814f58 ec2-50-16-11-77.compute-1.amazonaws.com ip-10-118-54-85.ec2.internal running 0 m1.small 2012-01-24T07:17:52+0000 us-east-1a aki-805ea7e9 monitoring-enabled 50.16.11.77 10.118.54.85 ebs paravirtual xen bfa8068e-a3a9-4374-8db0-7550010f477f sg-286ee441 default BLOCKDEVICE /dev/sda1 vol-8daea6e0 2012-01-24T07:18:15.000Z TAG instance i-5946af3c version2.0TAG instance i-5946af3c aws:autoscaling:groupName MyTagASG RESERVATION r-bbebf9da 629715795501 default INSTANCE i-2546af40 ami-31814f58 ec2-50-19-152-11.compute-1.amazonaws.com ip-10-116-241-173.ec2.internal running 0 m1.small 2012-01-24T07:17:53+0000 us-east-1a aki-805ea7e9 monitoring-enabled 50.19.152.11 10.116.241.173 ebs paravirtual xen 7d419c3a-0527-4970-80f5-b6467ce44849 sg-286ee441 default BLOCKDEVICE /dev/sda1 vol-89aea6e4 2012-01-24T07:18:18.000Z TAG instance i-2546af40 version2.0TAG instance i-2546af40 aws:autoscaling:groupName MyTagASG RESERVATION r-bfebf9de 629715795501 default INSTANCE i-2346af46 ami-31814f58 ec2-184-72-167-153.compute-1.amazonaws.com ip-10-203-54-74.ec2.internal running 0 m1.small 2012-01-24T07:17:54+0000 us-east-1a aki-805ea7e9 monitoring-enabled 184.72.167.153 10.203.54.74 ebs paravirtual xen ec0221df-0274-44e1-aa13-04b7f17442ef sg-286ee441 default BLOCKDEVICE /dev/sda1 vol-8baea6e6 2012-01-24T07:18:15.000Z TAG instance i-2346af46 aws:autoscaling:groupName MyTagASG TAG instance i-2346af46 version2.0
After you're finished using your instances and your Auto Scaling group, it is a good practice to clean up. Run the
as-delete-auto-scaling-group command with the optional --force-delete parameter. Force delete
specifies that EC2 instances that are part of the Auto Scaling group will be deleted with the Auto Scaling group, even if the instances are still running.
If you don't specify the --force-delete parameter, then you cannot delete your Auto Scaling group until you have manually stopped and terminated
all instances of that Auto Scaling group.
Run the command with the following values:
Auto Scaling group name = MyTagASG
Force delete (optional parameter) = --force-delete
Your command should look like the following example:
as-delete-auto-scaling-group MyTagASG --force-delete
Confirm that you want to delete the Auto Scaling group. After you confirm that you want to delete the Auto Scaling group, Auto Scaling deletes the group, as the following example shows:
Are you sure you want to delete this AutoScalingGroup? [Ny] OK-Deleted AutoScalingGroup
You just performed the following tasks:
Created a launch configuration.
Created an Auto Scaling group with a tag.
Confirmed that the Auto Scaling group has a tag and that the tag is applied to instances that the Auto Scaling group launched.
Changed the tag and Auto Scaling group, and confirmed that the changes are propagated to new instances launched.
Cleaned up.
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.
Note
The instance associated with the Auto Scaling group you just created is not launched immediately. So, if you run the snippet as a single code block, it could take a few minutes before you see the instance information.
as-create-launch-config MyTagLC --image-id ami-31814f58 --instance-type m1.small as-create-auto-scaling-group MyTagASG --launch-configuration MyTagLC --availability-zones us-east-1a --min-size 1 --max-size 10 --tag "k=version, v=1.0, p=true" as-describe-tags --filter "key1=version, key2=1.0" as-describe-auto-scaling-groups MyTagASG as-describe-auto-scaling-instances ec2-describe-instances i-33698556 as-create-or-update-tags --tag "id=MyTagASG, t=auto-scaling-group, k=version, v=2.0, p=true" as-update-auto-scaling-group MyTagASG --min-size 5 as-describe-auto-scaling-instances ec2-describe-instances as-delete-auto-scaling-group MyTagASG --force-delete