2

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?

β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Shravan
  • 141
  • 7

2 Answers2

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

Try this command:

aws ec2 describe-vpcs --query 'Vpcs[?contains(Tags[?Key==`Name`].Value[], `MyVPC`) == `true`].[VpcId]' --output text
krishna_mee2004
  • 6,556
  • 2
  • 35
  • 45