From c864e0f3947dc07d0894574d2d0f887f75c689b9 Mon Sep 17 00:00:00 2001 From: x p k Date: Wed, 4 May 2022 16:43:05 +0800 Subject: [PATCH] UPD: touch up format --- aws/aws-inventory.sh | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/aws/aws-inventory.sh b/aws/aws-inventory.sh index 2717900..feeec5e 100755 --- a/aws/aws-inventory.sh +++ b/aws/aws-inventory.sh @@ -1,37 +1,34 @@ #!/bin/bash +function formatprint() { + cat - > /tmp/formatprint.tmp + echo "# $1 ($(cat /tmp/formatprint.tmp | wc -l))" + cat /tmp/formatprint.tmp | sed -e 's/^/ /g' + rm -f /tmp/formatprint.tmp +} + # 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 '[\" ' +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 -echo "# RDS" -aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \" +aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier, DBInstanceClass, Engine, AllocatedStorage]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint RDS -echo "# elasticache" -aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \" +aws elasticache describe-cache-clusters --query 'CacheClusters[*].[CacheClusterId, CacheNodeType, Engine, EngineVersion]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint ElastiCache -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 \" +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 -echo "# VPC" -aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \" +aws ec2 describe-vpcs --query 'Vpcs[*].[VpcId, CidrBlock]' --output json | jq -cr '.[]|@csv' | tr -d \" | formatprint VPC -echo "# S3buckets" -aws s3api list-buckets --output text | awk '{print $NF}' +aws s3api list-buckets --output text | awk '{print $NF}' | formatprint S3Bucket -echo "# ECS" -aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}' +aws ecs list-clusters | jq -cr '.[][]' | awk -F/ '{print $NF}' | formatprint ECS -echo "# EKS" -aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}' +aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}' | formatprint EKS -echo "# CloudFront" -aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text +aws cloudfront list-distributions --query 'DistributionList.Items[*].[DomainName]' --output text | formatprint CloudFront -echo "# Route53Zones-RecordCount" -aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[*].[Name,ResourceRecordSetCount]' --output json | jq -cr '.[]|@csv' | tr -d \" | sort -k1 +aws --no-cli-pager route53 list-hosted-zones --query 'HostedZones[*].[Name,ResourceRecordSetCount]' --output json | jq -cr '.[]|@csv' | tr -d \" | sort -k1 | formatprint R53-RecordCount -echo "# IAM roles" -aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor +# echo "# IAM roles" +# aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor