Skip to content

Instantly share code, notes, and snippets.

@daveadams
Created July 31, 2020 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveadams/4bbd6978105788318aad98a03e38a70a to your computer and use it in GitHub Desktop.
Save daveadams/4bbd6978105788318aad98a03e38a70a to your computer and use it in GitHub Desktop.
Scan AWS usage and limits
#!/bin/bash
regions="us-east-1 us-west-2 us-east-2 ca-central-1 eu-west-1 eu-central-1 ap-southeast-1 ap-southeast-2"
acct=$( aws iam list-account-aliases |jq -r .AccountAliases[] )
echo "Account $acct"
echo
echo vCPU Limits: A, C, D, H, I, M, R, T, Z
echo ========================================
echo
for region in $regions; do
# not 100% accurate, if you are running any instance types other than A, C, D, H, I, M, R, T, X, and Z
printf "%-14s %6d / %6d\n" \
"$region" \
"$( tbq account=$acct region=$region | jq '.[].Data|select(.InstanceType[0:1] != "x")|.CpuOptions|.CoreCount * .ThreadsPerCore' | awk '{sum+=$1}END{print sum}' )" \
"$( aws service-quotas get-service-quota --region $region --service-code ec2 --quota-code L-1216C47A |jq .Quota.Value )"
done
echo
echo vCPU Limits: X
echo ========================================
echo
for region in $regions; do
vcpus="$( tbq account=$acct region=$region |jq '.[].Data|select(.InstanceType[0:1] == "x")|.CpuOptions|.CoreCount * .ThreadsPerCore' | awk '{sum+=$1}END{print sum}' )"
printf "%-14s %6d / %6d\n" \
"$region" \
"${vcpus:-0}" \
"$( aws service-quotas get-service-quota --region $region --service-code ec2 --quota-code L-7295265B |jq .Quota.Value )"
done
echo
echo ASG limits
echo ========================================
echo
for region in $regions; do
printf "%-14s %6d / %6d\n" \
"$region" \
"$( aws autoscaling describe-auto-scaling-groups --region $region |jq .AutoScalingGroups[].AutoScalingGroupName |wc -l )" \
"$( aws service-quotas get-service-quota --region $region --service-code autoscaling --quota-code L-CDE20ADC |jq .Quota.Value )"
done
echo
echo ALB limits
echo ========================================
echo
for region in $regions; do
printf "%-14s %6d / %6d\n" \
"$region" \
"$( aws elbv2 describe-load-balancers --region $region |jq .LoadBalancers[].LoadBalancerArn |wc -l )" \
"$( aws service-quotas get-service-quota --region $region --service-code elasticloadbalancing --quota-code L-53DA6B97 |jq .Quota.Value )"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment