2023-07-18 18:48:31 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
|
|
function list-resources-in-region {
|
2023-11-23 15:13:27 +08:00
|
|
|
echo "***"
|
|
|
|
echo -e "Region: $1"
|
|
|
|
echo "***"
|
2023-07-18 18:48:31 +08:00
|
|
|
echo -e "\n## EC2:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType,PrivateIpAddress]' --output json | jq -cr '.[][] | @tsv' | tr -d '[\" '
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## RDS:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## ElastiCache:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## ELB:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 elb describe-load-balancers --query 'LoadBalancerDescriptions[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## ALB:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## VPC:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@tsv' | tr -d \"
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## ECS_Clusters:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}'
|
2023-07-18 18:48:31 +08:00
|
|
|
|
|
|
|
echo -e "\n## EKS_Clusters:"
|
2023-07-18 19:44:06 +08:00
|
|
|
aws --region=$1 eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}'
|
|
|
|
|
2023-07-18 19:48:58 +08:00
|
|
|
echo -e "\n## EFS:"
|
|
|
|
aws --region=$1 efs describe-file-systems --output text
|
|
|
|
|
|
|
|
echo -e "\n## EMR:"
|
|
|
|
aws --region=$1 emr list-clusters --output text
|
|
|
|
|
2023-07-18 19:44:06 +08:00
|
|
|
# global resources
|
|
|
|
if [ $1 == "us-east-1" ]; then
|
|
|
|
echo -e "\n## Route53_zones:"
|
|
|
|
aws --region=$1 --no-cli-pager route53 list-hosted-zones --query 'HostedZones[].Name' --output text | tr '\t' '\n'
|
2023-07-18 18:48:31 +08:00
|
|
|
|
2023-07-18 19:44:06 +08:00
|
|
|
echo -e "\n## S3_Buckets:"
|
|
|
|
aws --region=$1 s3api list-buckets --output text | awk '{print $NF}'
|
2023-07-18 18:48:31 +08:00
|
|
|
|
2023-07-18 19:44:06 +08:00
|
|
|
echo -e "\n## Cloudfront:"
|
|
|
|
aws --region=$1 cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text
|
|
|
|
fi
|
2023-07-18 18:48:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate inventory of ec2, rds, lb, and s3 buckets.
|
2023-07-18 19:34:50 +08:00
|
|
|
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
|
2023-07-18 18:48:31 +08:00
|
|
|
|
2023-07-18 19:34:50 +08:00
|
|
|
# echo "This may take a moment..."
|
|
|
|
# sleep 50
|
2023-07-18 18:48:31 +08:00
|
|
|
|
2023-07-18 19:34:50 +08:00
|
|
|
#cat /tmp/aws-inventory*.txt
|
|
|
|
#rm -f /tmp/aws-inventory*.txt
|