Skip to content

Instantly share code, notes, and snippets.

@j3tm0t0
Created October 3, 2013 18:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save j3tm0t0/6814653 to your computer and use it in GitHub Desktop.
Save j3tm0t0/6814653 to your computer and use it in GitHub Desktop.
count instance number by type in all regions across accounts
#!/bin/sh
if [ "$1" = "" ]
then
echo "usage: $0 [AccountID1] ( [AccountID2] [AccountID3] ...)"
exit
fi
for account in $*
do
echo accountid: $account
export AWS_ACCESS_KEY_ID=ACCESSKEY
export AWS_SECRET_ACCESS_KEY=SECRETKEY
unset AWS_SECURITY_TOKEN
CREDENTIALS=`aws sts assume-role --role-arn arn:aws:iam::$account:role/cross --role-session-name cross --output text | grep ^CREDENTIALS`
set -- $CREDENTIALS
export AWS_ACCESS_KEY_ID=$5
export AWS_SECRET_ACCESS_KEY=$2
export AWS_SECURITY_TOKEN=$3
export AWS_DEFAULT_REGION=us-east-1
for region in `aws ec2 describe-regions --output text | cut -f 2`
do
echo "-- $region"
aws ec2 describe-instances --region $region --filters Name=instance-state-name,Values=running --output json | jq .Reservations[].Instances[].InstanceType | sort | uniq -c
echo
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment