Skip to content

Instantly share code, notes, and snippets.

@mvisonneau
Last active April 26, 2023 08:26
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 mvisonneau/80d378f8e2603bae234018cbaddb164f to your computer and use it in GitHub Desktop.
Save mvisonneau/80d378f8e2603bae234018cbaddb164f to your computer and use it in GitHub Desktop.
AMI cost estimate
#!/usr/bin/env bash
REGIONS=$(aws ec2 describe-regions | jq -r '.Regions[].RegionName' | sort)
TOTAL_SIZE=0
TOTAL_COST=0
for REGION in $REGIONS; do
SIZE=$(AWS_REGION=$REGION aws ec2 describe-snapshots --owner-ids self --query "Snapshots[*].{Description:Description,VolumeSize:VolumeSize}" | jq '[.[] | select( (.Description|startswith("Copied for DestinationAmi")) or (.Description|startswith("Created by CreateImage")) ) | .VolumeSize] | add')
COST=$(bc -l <<< "$SIZE * 0.05")
TOTAL_SIZE=$(bc -l <<< "$TOTAL_SIZE + $SIZE")
TOTAL_COST=$(bc -l <<< "$TOTAL_COST + $COST")
echo "${REGION}: ${SIZE}Gi -> \$${COST}/mo"
done
echo "Total: ${TOTAL_SIZE}Gi -> \$${TOTAL_COST}/mo"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment