code-dumps/aws/aws-inventory.sh

38 lines
1.7 KiB
Bash
Raw Normal View History

2021-11-29 16:16:51 +08:00
#!/bin/bash
# Generate inventory of ec2, rds, lb, and s3 buckets.
echo "# EC2"
2022-01-19 10:41:03 +08:00
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType]' --output json | jq -cr '.[][] | @csv' | tr -d '[\" '
2021-11-29 16:16:51 +08:00
echo "# RDS"
2022-01-19 10:41:03 +08:00
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \"
2021-11-29 16:16:51 +08:00
echo "# elasticache"
2022-01-19 10:41:03 +08:00
aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \"
2021-11-29 16:16:51 +08:00
2022-01-19 10:41:03 +08:00
echo "# LB"
aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@csv' | tr -d \"
aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,DNSName,Scheme]' --output json | jq -cr '.[]|@csv' | tr -d \"
2021-11-29 17:58:15 +08:00
2021-11-29 16:16:51 +08:00
echo "# VPC"
2022-01-19 10:41:03 +08:00
aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \"
2021-11-29 16:16:51 +08:00
echo "# S3buckets"
2022-01-19 10:41:03 +08:00
aws s3api list-buckets --output text | awk '{print $NF}'
2021-11-29 16:16:51 +08:00
echo "# ECS"
2022-01-19 10:41:03 +08:00
aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}'
2021-11-29 16:16:51 +08:00
echo "# EKS"
2022-01-19 10:41:03 +08:00
aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}'
2021-11-29 16:16:51 +08:00
echo "# CloudFront"
2022-01-19 10:41:03 +08:00
aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text
echo "# Route53Zones-RecordCount"
aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[*].[Name,ResourceRecordSetCount]' --output json | jq -cr '.[]|@csv' | tr -d \" | sort -k1
2021-11-29 16:33:17 +08:00
echo "# IAM roles"
2022-01-19 10:41:03 +08:00
aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor