Is there a way to list down the available AutoScalingGroups under an account and filter on top of it based on some tags?
I am looking for something like aws ecs list-clusters
which gives list of ecs clusters.
Yes. You can use JMESPath syntax to filter the results of aws autoscaling describe-auto-scaling-groups
command down to only those groups matching some tag's key/value pair. This uses the --query
parameter, which is available for filtering on most AWS CLI commands.
Example to query by a single tag:
The example below filters results based on a tag where Key = 'Environment' and Value = 'Dev'.
aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[? Tags[? (Key=='Environment') && Value=='Dev']]".AutoScalingGroupName
Example to query by multiple tags:
The example below filters results based on tags where Key = 'Environment' and Value = 'Dev', and Key = 'Name' and Value = 'MyValue'. This uses a pipe to query for the second tag on the resulting autoscaling groups of the query for the first tag.
aws autoscaling describe-auto-scaling-groups --query "AutoScalingGroups[? Tags[? (Key=='Environment') && Value=='Dev']] | [? Tags[? Key=='Name' && Value =='MyValue']]".AutoScalingGroupName
The below AWS CLI command gives Auto Scaling Group with Tag having Key
== Product
and Value
== test
for a profile of account1
aws --profile account1 autoscaling describe-auto-scaling-groups \
--query 'AutoScalingGroups[?contains(Tags[?Key==`Product`].Value, `test`)].[AutoScalingGroupName]' --region eu-west-1 --output table
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.