1
votes

I am trying to list down all the regions for which my AWS VPC is configured.

The following commands are of no use to me, since: aws ec2 describe-vpcs Only lists VPC details but not the region

aws ec2 describe-availability-zones Lists all the availability zones available for me.

I do see the specific AZs for my subnets under: AWS Console --> VPC --> Summary --> Network ACL --> Subnet Associations

But I would like to list the same on the command line for my VPC. Is this possible?

2

2 Answers

5
votes

An Amazon VPC exists only in one region. There is no multi-region capability for VPCs.

The VPC will be in the region to which you issue the above commands. Therefore, you must already know the region before issuing any of these commands.

If you merely want a list of regions (unrelated to a particular VPC), use describe-regions:

aws ec2 describe-regions
0
votes

Yes it possible using the shellscript. At time you can list only one region Resources using AWS CLI.

#!/bin/bash
Profile='Enter_your_profile_name'
while read f1 f2
      do 
      Region=$f1
      Region_Name=$f2
      echo "$Region - $Region_Name \n" >> vpc-details.csv
      aws ec2 describe-vpcs --profile $Profile --region $Region --output text --query 'Vpcs[].[Tags[?Key==`Name`].Value | [0],CidrBlock,VpcId,IsDefault]' --filter Name=isDefault,Values=false >> vpc-details.csv
      echo "\n" >> vpc-details.csv  
done < region.txt

region.txt

  • us-east-2 US-East(Ohio) us-east-1 US-East(N-Virginia)
  • us-west-1 US-West(N-California) us-west-2 US-West-(Oregon)
  • ap-northeast-1 Asia-Pacific-(Tokyo)
  • ap-northeast-2 Asia-Pacific-(Seoul) ap-south-1 Asia-Pacific-(Mumbai)
  • ap-southeast-1 Asia-Pacific-(Singapore)
  • ap-southeast-2 Asia-Pacific-(Sydney) ca-central-1 Canada-(Central)
  • eu-central-1 EU -Frankfurt) eu-west-1 EU-(Ireland)
  • eu-west-2 EU-(London) eu-west-3 EU-(Paris)
  • sa-east-1 South-America-(São-Paulo)

Sample output

eu-west-1 - EU-(Ireland)

Testining   10.135.0.0/16   vpc-xxxx    False
VPC_prod    10.140.0.0/16   vpc-zzzz    False

Note: - you will be getting the following output

  • Name of the VPC
  • CIDR range
  • VPC-ID
  • Is the VPC is default or not

You have to give your profile variable to make it work... Let me know if you have any query.