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" |
参考: AWSのCloudWatchで取得できるBillingの情報を毎日Slackに通知させて費用を常に把握する – さよならインターネット
参考URLだと ruby で処理してるけど、aws-cli, jq と curl 使ってるだけだから、ruby 使わなくても sh だけでいいんでないかなーと思った
コメントを残す