Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[AWS-CLI] 昨日までのAWSの利用費をCloudWatchから取ってきて、スラックに通知するシェルスクリプト
# 昨日の日付
yesterday=`date -d '1 days ago' +%Y-%m-%d`
# 一日分の 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 -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
You can’t perform that action at this time.