LoginSignup
1
2

More than 5 years have passed since last update.

CloudWatchのデータをAWS CLIで取得する

Posted at

検索したらrubyスクリプトの例が多かったのでメモ

やりたいこと

  • S3の課金額をシェルスクリプトで取得したい

参考資料

スクリプト

  • Mac向け。他環境の場合はdateコマンド周りを読み替えてください
  • 値だけ欲しかったので適当にcutしてます
  • jqコマンドはない前提
aws cloudwatch --region us-east-1 get-metric-statistics \                                                                                           
--namespace 'AWS/Billing' \
--metric-name EstimatedCharges \
--start-time "$(date -v-1d +'%Y-%m-%d 00:00:00')" \
--end-time "$(date +'%Y-%m-%d 00:00:00')" \
--period 86400 \
--statistics 'Sum' \
--dimensions 'Name=Currency,Value=USD' | grep Sum | awk '{print $2}' | cut -d"," -f1
#=> 10.000000000000001 といった感じで表示される

引っかかったところ

  • 「--dimensions」はリファレンス上は非必須だが指定しないと値が取れない模様
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2