
Using AWS CLI to find all VPC subnets with a specific a tag
The following describe-subnets example uses a filter to retrieve the details of those subnets with the tag VPCname=HappyVPC and the --query parameter to display the subnet IDs of the subnets with this tag. You can replace the key pair value to your own tags you to filter in your account.
for region in `aws ec2 describe-regions --query "Regions[].RegionName" --region us-east-1 --output text`
do
echo "[${region}]"
aws ec2 describe-subnets --filters "Name=tag:VPCname,Values=HappyVPC" --query "Subnets[*].SubnetId" --output text --region ${region}
done
echo "finished"