Skip to content

Instantly share code, notes, and snippets.

@sechiro
Last active April 1, 2019 06:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sechiro/8561684 to your computer and use it in GitHub Desktop.
Save sechiro/8561684 to your computer and use it in GitHub Desktop.
aws cliを使って料金を確認。リージョンは「us-east-1」固定(※1)。 ディメンションも「--dimensions Name=Currency,Value=USD」が必須。jqを入れているのは、タイムスタンプ順にソートするため。※1 http://aws.amazon.com/jp/billing/faqs/#Can_I_view_estimated_charge_metrics_or_set_billing_alerts_in_a_region_other_than_US-East
#!/bin/bash
namespace=AWS/Billing
os_name=`uname`
now=`date -u "+%Y-%m-%dT%H:%M:%SZ"`
if [ $os_name = "Darwin" ]; then
yesterday=`date -u -v-1d "+%Y-%m-%dT%H:%M:%SZ"`
else
yesterday=`date -u -d "1 days ago" "+%Y-%m-%dT%H:%M:%SZ"`
fi
start_time=${1:-$yesterday}
end_time=${2:-$now}
period=300
metric=EstimatedCharges
aws cloudwatch get-metric-statistics \
--region us-east-1 \
--namespace $namespace \
--metric-name $metric \
--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