Use tags to filter Auto Scaling groups
The following examples show you how to use filters with the describe-auto-scaling-groups command to describe Auto Scaling groups with specific tags. Filtering by tags is limited to the Amazon CLI or an SDK, and is not available from the console.
Filtering considerations
-
You can specify multiple filters and multiple filter values in a single request.
-
You cannot use wildcards with the filter values.
-
Filter values are case-sensitive.
Example: Describe Auto Scaling groups with a specific tag key and value pair
The following command shows how to filter results to show only Auto Scaling groups
with the tag key and value pair of
.environment=production
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-key,Values=
environment
Name=tag-value,Values=production
The following is an example response.
{
"AutoScalingGroups": [
{
"AutoScalingGroupName": "my-asg",
"AutoScalingGroupARN": "arn
",
"LaunchTemplate": {
"LaunchTemplateId": "lt-0b97f1e282EXAMPLE",
"LaunchTemplateName": "my-launch-template",
"Version": "$Latest"
},
"MinSize": 1,
"MaxSize": 5,
"DesiredCapacity": 1,
...
"Tags": [
{
"ResourceType": "auto-scaling-group",
"ResourceId": "my-asg",
"PropagateAtLaunch": true,
"Value": "production",
"Key": "environment"
}
],
...
},
... additional groups ...
]
}
Alternatively, you can specify tags using a
tag:
filter. For example, the
following command shows how to filter results to show only Auto Scaling groups with a tag
key and value pair of <key>
.
This filter is formatted as follows:
environment=production
Name=tag:
,
with <key>
,Values=<value>
<key>
and <value>
representing a tag key and value pair.
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag:
environment
,Values=production
You can also filter Amazon CLI output by using the --query
option. The
following example shows how to limit Amazon CLI output for the previous command to the
group name, minimum size, maximum size, and desired capacity attributes only.
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag:
environment
,Values=production
\ --query "AutoScalingGroups[].{AutoScalingGroupName: AutoScalingGroupName, MinSize: MinSize, MaxSize: MaxSize, DesiredCapacity: DesiredCapacity}"
The following is an example response.
[
{
"AutoScalingGroupName": "my-asg",
"MinSize": 0,
"MaxSize": 10,
"DesiredCapacity": 1
},
... additional groups ...
]
For more information about filtering, see Filtering Amazon CLI output in the Amazon Command Line Interface User Guide.
Example: Describe Auto Scaling groups with tags that match the tag key specified
The following command shows how to filter results to show only Auto Scaling groups
with the
tag, regardless of the
tag value.environment
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-key,Values=
environment
Example: Describe Auto Scaling groups with tags that match the set of tag keys specified
The following command shows how to filter results to show only Auto Scaling groups
with tags for
and
environment
, regardless of the tag
values.project
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-key,Values=
environment
Name=tag-key,Values=project
Example: Describe Auto Scaling groups with tags that match at least one of the tag keys specified
The following command shows how to filter results to show only Auto Scaling groups
with tags for
or
environment
, regardless of the tag
values.project
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-key,Values=
environment
,project
Example: Describe Auto Scaling groups with the specified tag value
The following command shows how to filter results to show only Auto Scaling groups
with a tag value of
, regardless
of the tag key.production
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-value,Values=
production
Example: Describe Auto Scaling groups with the set of tag values specified
The following command shows how to filter results to show only Auto Scaling groups
with the tag values
and
production
, regardless of the tag
key.development
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-value,Values=
production
Name=tag-value,Values=development
Example: Describe Auto Scaling groups with tags that match at least one of the tag values specified
The following command shows how to filter results to show only Auto Scaling groups
with a tag value of
or
production
, regardless of the tag
key.development
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag-value,Values=
production
,development
Example: Describe Auto Scaling groups with tags that match multiple tag keys and values
You can also combine filters to create custom AND and OR logic to do more complex filtering.
The following command shows how to filter results to show only Auto Scaling groups with a
specific set of tags. One tag key is
AND the tag value is (environment
OR
production
) AND the other tag
key is development
AND the tag value is
costcenter
.cc123
aws autoscaling describe-auto-scaling-groups \ --filters Name=tag:
environment
,Values=production
,development
Name=tag:costcenter
,Values=cc123