Created
April 22, 2018 14:25
-
-
Save guessi/8a2f2eb9696f7474341d4d08e2b704da to your computer and use it in GitHub Desktop.
Helper Script for AWS Billing Infomation
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
#!/bin/bash | |
# | |
# original edition: | |
# - https://gist.github.com/sechiro/8561684 | |
# | |
now=`date -u "+%Y-%m-%dT%H:%M:%SZ"` | |
if [ $(uname) = "Darwin" ]; then | |
yesterday=`date -u -v-3d "+%Y-%m-%dT%H:%M:%SZ"` | |
else | |
yesterday=`date -u -d "3 days ago" "+%Y-%m-%dT%H:%M:%SZ"` | |
fi | |
start_time=${1:-$yesterday} | |
end_time=${2:-$now} | |
period=${3:-3600} | |
aws cloudwatch get-metric-statistics \ | |
--profile billing \ | |
--region us-east-1 \ | |
--namespace AWS/Billing \ | |
--metric-name EstimatedCharges \ | |
--start-time ${start_time} \ | |
--end-time ${end_time} \ | |
--period ${period} \ | |
--statistics "Maximum" \ | |
--dimensions Name=Currency,Value=USD | \ | |
jq '.Datapoints | sort_by(.Timestamp)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment