Skip to content

Instantly share code, notes, and snippets.

@guessi
Created April 22, 2018 14:25
Show Gist options
  • Save guessi/8a2f2eb9696f7474341d4d08e2b704da to your computer and use it in GitHub Desktop.
Save guessi/8a2f2eb9696f7474341d4d08e2b704da to your computer and use it in GitHub Desktop.
Helper Script for AWS Billing Infomation
#!/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