26 lines
854 B
Bash
Executable File
26 lines
854 B
Bash
Executable File
#!/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
|
|
}
|
|
|
|
function listEc2() {
|
|
aws --region=$1 ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress, Placement.AvailabilityZone]' --output json | jq -cr '.[][] | @csv' | tr -d '[\" '
|
|
}
|
|
|
|
export -f formatprint
|
|
export -f listEc2
|
|
|
|
# Generate inventory of ec2 in all regions
|
|
|
|
echo "InstanceId,NameTag,OsPlatform,InstanceType,PrivateIp,AZ"
|
|
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
|
sem -j6 listEc2 $r
|
|
done
|
|
|
|
sem --wait
|