Search code examples
amazon-web-servicesamazon-ec2aws-clijmespath

AWS CLI - JMESPath query to find vpc-id by tag


I want to list the VPC id's which have a particular tag (Name=MyVPC).

I am aware that I can use --filter and run:

aws ec2 describe-vpcs --filters Name=tag:Name,Values=MyVPC --query 'Vpcs[].VpcId'

This works completely fine.

Is there a way I can achieve this without using --filter and only use JMESPath?


Solution

  • aws ec2 describe-vpcs --query 'Vpcs[?Tags[?Key==`Name`]|[?Value==`MyVPC`]].VpcId' --output text