[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