2022-09-07 10:31:34 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function formatprint() {
|
|
|
|
cat - > /tmp/formatprint.tmp
|
|
|
|
echo "# $1 ($(cat /tmp/formatprint.tmp | wc -l))"
|
|
|
|
#cat /tmp/formatprint.tmp | sed -e 's/^/ /g'
|
|
|
|
cat /tmp/formatprint.tmp | column -t -s, | sed -e 's/^/ /g'
|
|
|
|
rm -f /tmp/formatprint.tmp
|
|
|
|
}
|
|
|
|
|
2023-07-18 18:48:31 +08:00
|
|
|
# Generate inventory of ec2 in all regions
|
2022-09-07 10:31:34 +08:00
|
|
|
|
2023-07-18 18:48:31 +08:00
|
|
|
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
|
|
|
echo "Region: $r"
|
|
|
|
aws --region=$r ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress, PublicIpAddress]' --output json | jq -cr '.[][] | @csv' | tr -d '[\" ' | formatprint EC2
|
|
|
|
done
|