Last active
April 26, 2023 08:26
-
-
Save mvisonneau/80d378f8e2603bae234018cbaddb164f to your computer and use it in GitHub Desktop.
AMI cost estimate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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