Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andytumelty/3651ef79fc00908b4d9f5f6bba05489a to your computer and use it in GitHub Desktop.
Save andytumelty/3651ef79fc00908b4d9f5f6bba05489a to your computer and use it in GitHub Desktop.
AWS CLI List VPC ID, Name and CIDR Block
# display VPC ID, CIDR Block and Name
aws ec2 --output text --query 'Vpcs[*].{VpcId:VpcId,Name:Tags[?Key==`Name`].Value|[0],CidrBlock:CidrBlock}' describe-vpcs
@smohan7
Copy link

smohan7 commented Aug 31, 2023

The above command give only the first CIDR block but how to get multiple CIDR block in a VPC, if the "CidrBlockAssociationSet" contains multiple CIDR blocks? I am using this way.
aws ec2 --query 'Vpcs[*].{a:Tags[?Key==Name].Value|[0], b:VpcId, Cidr:CidrBlockAssociationSet[*].CidrBlock}' describe-vpcs

@astrikmobilize
Copy link

astrikmobilize commented Feb 15, 2024

aws ec2 --query 'Vpcs[*].{name:Tags[?Key==`Name`].Value|[0], VpcId:VpcId, Cidr:CidrBlockAssociationSet[*].CidrBlock}' describe-vpcs --profile ${request_account}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment