Skip to content

Instantly share code, notes, and snippets.

@kenzo0107
Created December 1, 2023 07:09
Show Gist options
  • Save kenzo0107/e603d8a4d0ceff0b70319b0426400598 to your computer and use it in GitHub Desktop.
Save kenzo0107/e603d8a4d0ceff0b70319b0426400598 to your computer and use it in GitHub Desktop.
show list of running AWS resources
#!/bin/bash
profiles=(
<profile names in ~/.aws/credentials>
)
for profile in ${profiles[@]}; do
awsume $profile --session-name "kenzo.tanaka" --output-profile tmp > /dev/null 2>&1
account_id=$(aws sts get-caller-identity --profile tmp --query 'Account' --output text)
if [ -z "$account_id" ]; then
continue
fi
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 describe-db-clusters だと cluster を利用していない場合に instance 情報が取得できない
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment