Last active
September 3, 2024 15:19
-
-
Save andytumelty/3651ef79fc00908b4d9f5f6bba05489a to your computer and use it in GitHub Desktop.
AWS CLI List VPC ID, Name and CIDR Block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
aws ec2 --query 'Vpcs[*].{name:Tags[?Key==`Name`].Value|[0], VpcId:VpcId, Cidr:CidrBlockAssociationSet[*].CidrBlock}' describe-vpcs --profile ${request_account}
You also need to add --region
, or it will only list the region from your default profile.
aws ec2 --query 'Vpcs[*].{name:Tags[?Key==`Name`].Value|[0], VpcId:VpcId, Cidr:CidrBlockAssociationSet[*].CidrBlock}' describe-vpcs --profile ${request_account} --region ${region}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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