#!/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. # aws eks list-clusters | jq '.[][]' | awk -F/ '{print $NF}' | formatprint EKS # IAM roles" # aws iam list-roles | jq -cr '.Roles[] | .RoleName' | grep -v AWSServiceRoleFor # IAM users aws iam list-roles --page-size 100| jq -cr '.Roles[] | .RoleName ' | while read r; do echo "Role: $r" aws iam list-attached-role-policies --role-name $r | jq -cr '.AttachedPolicies[] | .PolicyArn' | formatprint RoleManagedPolicies aws iam list-role-policies --role-name $r | jq -cr '.PolicyNames[]' | formatprint RoleInlinePolicies echo "" done