code-dumps/aws/aws-inventory.sh

36 lines
2.0 KiB
Bash
Raw Normal View History

2021-11-29 16:16:51 +08:00
#!/bin/bash
2022-05-04 16:43:05 +08:00
function formatprint() {
cat - > /tmp/formatprint.tmp
echo "# $1 ($(cat /tmp/formatprint.tmp | wc -l))"
2022-05-13 17:14:52 +08:00
#cat /tmp/formatprint.tmp | sed -e 's/^/ /g'
cat /tmp/formatprint.tmp | column -t -s, | sed -e 's/^/ /g'
2022-05-04 16:43:05 +08:00
rm -f /tmp/formatprint.tmp
}
2021-11-29 16:16:51 +08:00
# Generate inventory of ec2, rds, lb, and s3 buckets.
2022-05-04 16:43:05 +08:00
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
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint RDS
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint ElastiCache
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
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
2021-11-29 17:58:15 +08:00
2022-05-04 16:43:05 +08:00
aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint VPC
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws s3api list-buckets --output text | awk '{print $NF}' | formatprint S3Bucket
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}' | formatprint ECS
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}' | formatprint EKS
2021-11-29 16:16:51 +08:00
2022-05-04 16:43:05 +08:00
aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text | formatprint CloudFront
2022-01-19 10:41:03 +08:00
2022-05-04 16:43:05 +08:00
aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[*].[Name,ResourceRecordSetCount]' --output json | jq -cr '.[]|@csv' | tr -d \" | sort -k1 | formatprint R53-RecordCount
2021-11-29 16:33:17 +08:00
2022-05-04 16:43:05 +08:00
# echo "# IAM roles"
# aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor