The cool thing about this script is that it uses par-each
to run the aws commands in parallel and collecting the results. Do you know how hard that is to do in bash?!
Warning
This script assumes that you have 1 profile entry for each AWS account of the form <account alias>/aws-read-only
.
Adapt as needed.
aws configure list-profiles | grep aws-read-only | lines | par-each {|profile|
let account = $profile | split row '/' | first
aws --profile $profile ec2 describe-regions --output json | from json | get Regions | par-each {|elem|
print --stderr $"Getting VPCs for ($profile) in ($elem.RegionName)"
aws --profile $profile --region $elem.RegionName ec2 describe-vpcs --output json | from json | get Vpcs
| where IsDefault == false
| default [] Tags
| select CidrBlock Tags
| insert account $account
| insert region $elem.RegionName
| update Tags {where $it.Key == Name | get 0?.Value}
} | flatten
} | flatten | sort-by CidrBlock