Skip to content

Instantly share code, notes, and snippets.

@wokamoto
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wokamoto/418ac1585db1107caa01 to your computer and use it in GitHub Desktop.
Save wokamoto/418ac1585db1107caa01 to your computer and use it in GitHub Desktop.
[AWS-CLI] 昨日までのAWSの利用費をCloudWatchから取ってきて、スラックに通知するシェルスクリプト
#!/bin/sh
# 昨日の日付
yesterday=`date -d '1 days ago' +%Y-%m-%d`
# 一日分の Maximum 値を使って
period='86400'
statistics='Maximum'
# CloudWatchからBillingのデータを持ってくる
billing=`aws --region us-east-1 cloudwatch get-metric-statistics \
--namespace 'AWS/Billing' \
--dimensions "Name=Currency,Value=USD" \
--metric-name EstimatedCharges \
--start-time "${yesterday} 00:00:00" \
--end-time "${yesterday} 23:59:59" \
--period ${period} --statistics "${statistics}" \
| jq ".Datapoints[].${statistics}"`
strings="${yesterday}までのAWSの利用費(月毎)です。 EstimatedCharges : \$${billing}"
# DevOpsManに伝える
curl -s https://slack.com/api/chat.postMessage -X POST \
-d "channel=#CHANNEL" \
-d "text=${strings}" \
-d "username=USER" \
-d "icon_emoji=:ICON:" \
-d "token=xoxp-0000000000-0000000000-0000000000-000000"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment