55 lines
2.2 KiB
Bash
Executable File
55 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
|
|
function list-resources-in-region {
|
|
export AWS_DEFAULT_REGION=$1
|
|
echo "---"
|
|
echo "# Region: $1"
|
|
echo "---"
|
|
echo -e "\n## EC2:"
|
|
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress]' --output json | jq -cr '.[][] | @tsv' | tr -d '[\" '
|
|
|
|
echo -e "\n## RDS:"
|
|
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
|
|
|
echo -e "\n## ElastiCache:"
|
|
aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
|
|
|
echo -e "\n## ELB:"
|
|
aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
|
|
|
echo -e "\n## ALB:"
|
|
aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
|
|
|
echo -e "\n## VPC:"
|
|
aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
|
|
|
echo -e "\n## S3_Buckets:"
|
|
aws s3api list-buckets --output text | awk '{print $NF}'
|
|
|
|
echo -e "\n## ECS_Clusters:"
|
|
aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}'
|
|
|
|
echo -e "\n## EKS_Clusters:"
|
|
aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}'
|
|
|
|
echo -e "\n## Cloudfront:"
|
|
aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text
|
|
|
|
echo -e "\n## Route53_zones:"
|
|
aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[].Name' --output text
|
|
}
|
|
|
|
# Generate inventory of ec2, rds, lb, and s3 buckets.
|
|
export -f list-resources-in-region
|
|
aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | parallel list-resources-in-region {}
|
|
#aws --region=us-east-1 ec2 describe-regions --query Regions[].RegionName --output text | sed -e 's/\t/\n/g' | while read r; do
|
|
# list-resources-in-region $r > /tmp/aws-inventory-$r.txt &
|
|
#done
|
|
|
|
# echo "This may take a moment..."
|
|
# sleep 50
|
|
|
|
#cat /tmp/aws-inventory*.txt
|
|
#rm -f /tmp/aws-inventory*.txt
|