Last active
August 29, 2015 14:19
-
-
Save wokamoto/418ac1585db1107caa01 to your computer and use it in GitHub Desktop.
[AWS-CLI] 昨日までのAWSの利用費をCloudWatchから取ってきて、スラックに通知するシェルスクリプト
This file contains 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/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