How to filltering over tags and values aws cli

Viewed 152

Hi I would like to use AWS CLI fillters to find the security group. I found in tutorial command i should use, but it doesn't work.

aws ec2 describe-security-groups --filters Name=key,Values="xxx"  --profile dev 

I have a few security groups with tags with schema like this:

tags:
- Key : aws-security-group05
  Value : 1.0.1.1

And I want to find ID of security group by fillterring by tags and values.

1 Answers

You have to provide correct syntax like below-

For example, if you want to list down all security groups which are having a tag named as Department and the value of that tag is HR,

aws ec2 describe-security-groups --filters Name=tag:Department,Values=HR

for your case it would be -

aws ec2 describe-security-groups --filters Name=tag:aws-security-group05,Values=1.0.1.1

above command will display all the details about security group, if you just want to see id of the security group, pls use --query parameter

example-

aws ec2 describe-security-groups --filters Name=tag:aws-security-group05,Values=1.0.1.1 --query 'SecurityGroups[].GroupId' --out text

Related