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