'AWS-CLI: How do I filter autoscalinggroups

Unable to find example to use filters https://docs.aws.amazon.com/cli/latest/reference/autoscaling/describe-auto-scaling-groups.html#options



Solution 1:[1]

Try with the following command:

aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`eks:nodegroup-name`].Value, `cassandra`)]' --region [AWS_REGION]

Or if you only want the ASG name you can filter it using:

aws autoscaling describe-auto-scaling-groups --query 'AutoScalingGroups[?contains(Tags[?Key==`eks:nodegroup-name`].Value, `cassandra`)].[AutoScalingGroupName]' --region [AWS_REGION]

Reference:

Filtering AWS CLI output

Solution 2:[2]

Try something like:

aws ec2 describe-instances --filters "Name=tag:Name,Values=xxx" "Name=tag:env,Values=dev"

more

UPDATE: I believe you need the tag: or tag-key: per the error message you provided, as in the example above: The filter criteria isn't valid. Valid filter types for the Name attribute of filters are: tag-key, tag-value and tag:<key>. The confusing part is that your tag has the : (COLON) character (more), which either needs escaped or not used or replaced.

aws autoscaling describe-auto-scaling-groups --filters "Name=tag:\"eks:nodegroup-name\",Values=cassandra"

Solution 3:[3]

I tried the same without double quotes with the filters, and it worked.

aws autoscaling describe-auto-scaling-groups --filters Name=tag:\eks:nodegroup-name\,Values=cassandra

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 OARP
Solution 2
Solution 3 arun Kaliappan