code-dumps/aws/aws-inventory.sh
2022-01-19 10:41:03 +08:00

38 lines
1.7 KiB
Bash
Executable File

#!/bin/bash
# Generate inventory of ec2, rds, lb, and s3 buckets.
echo "# EC2"
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId, Tags[?Key==`Name`].Value[] | [0], PlatformDetails, InstanceType]' --output json | jq -cr '.[][] | @csv' | tr -d '[\" '
echo "# RDS"
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \"
echo "# elasticache"
aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \"
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 \"
echo "# VPC"
aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \"
echo "# S3buckets"
aws s3api list-buckets --output text | awk '{print $NF}'
echo "# ECS"
aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}'
echo "# EKS"
aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}'
echo "# CloudFront"
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
echo "# IAM roles"
aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor