To list all the VPCs for an AWS account in all the regions, you can use the AWS Command Line Interface (CLI) with a script that iterates through each region and retrieves the VPC information.
Here’s an example script using Bash:
bashCopy code
#!/bin/bash
# Retrieve all AWS regions
regions=$(aws ec2 describe-regions --query "Regions[].RegionName" --output text)
# Iterate over each region
for region in $regions; do
echo "Region: $region"
# Retrieve VPC information for the current region
vpcs=$(aws ec2 describe-vpcs --region $region --query "Vpcs[].VpcId" --output text)
# Check if VPCs exist in the region
if [ -n "$vpcs" ]; then
echo "VPCs:"
# Iterate over each VPC and display its ID
for vpc in $vpcs; do
echo " $vpc"
done
else
echo "No VPCs found in this region."
fi
echo
done
Here’s how you can use this script:
- Ensure you have the AWS CLI installed and configured with your AWS account credentials.
- Create a new file with a
.sh
extension, e.g.,list_vpcs.sh
. - Copy and paste the script into the file.
- Save the file and exit.
- Open a terminal or command prompt.
- Navigate to the directory where you saved the script.
- Run the script using the following command:
bash list_vpcs.sh
.
The script will iterate over each AWS region, retrieve the VPC information for each region, and display the VPC IDs.