code-dumps/aws/aws-ec2-inventory.sh

15 lines
567 B
Bash
Raw Normal View History

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
}
# Generate inventory of ec2, rds, lb, and s3 buckets.
aws 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