#!/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 --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do export AWS_DEFAULT_REGION=$r echo "---" echo "# Region: $r" echo "---" aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress]' --output json | jq -cr '.[][] | @csv' | tr -d '[\" ' | formatprint EC2 aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint RDS aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint ElastiCache aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint ELB aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint ALB aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint VPC aws s3api list-buckets --output text | awk '{print $NF}' | formatprint S3Bucket aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}' | formatprint ECS aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}' | formatprint EKS aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text | formatprint CloudFront aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[*].[Name,ResourceRecordSetCount]' --output json | jq -cr '.[]|@csv' | tr -d \" | sort -k1 | formatprint R53-RecordCount done # echo "# IAM roles" # aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor