1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #!/bin/bash
profiles=( <profile names in ~/.aws/credentials> )
for profile in ${profiles[@]}; do awsume $profile --session-name "kenzo.tanaka" --output-profile tmp account_id=$(aws sts get-caller-identity --profile tmp --query 'Account' --output text)
aws ec2 --profile tmp describe-instances --filters "Name=instance-state-name,Values=running" \ | jq -r ".Reservations[].Instances[] | \"$profile,$account_id,ec2,\"+ .InstanceType +\",1,\"+ (.Tags[]|select(.Key == \"Name\").Value)"
aws rds --profile tmp describe-db-instances \ | jq -r ".DBInstances[] | select(.DBInstanceStatus==\"available\") | \"$profile,$account_id,\"+ .Engine +\",\"+ .DBInstanceClass +\",1,\"+ .DBInstanceIdentifier"
aws elasticache --profile tmp describe-cache-clusters \ | jq -r ".CacheClusters[] | \"$profile,$account_id,\"+ .Engine +\",\"+ .CacheNodeType +\",\"+ (.NumCacheNodes|tostring) +\",\"+ .CacheClusterId"
aws redshift --profile tmp describe-clusters \ | jq -r ".Clusters[] | select(.ClusterStatus==\"available\") | \"$profile,$account_id,redshift,\"+ .NodeType +\",\"+ (.NumberOfNodes|tostring) +\",\"+ .ClusterIdentifier" done
|