Last active
August 29, 2015 14:21
-
-
Save king-panda/8e40cca844a11e2beacf to your computer and use it in GitHub Desktop.
【Hubot】AWSの利用料金を聞くと答えてくれるようにした ref: http://qiita.com/kingpanda/items/aa1b24ffd12dd81f1ab2
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
execsyncs = require('execsyncs') | |
module.exports = (robot) -> | |
robot.respond /aws_bill/i, (msg) -> | |
result = '' + execsyncs('sh 「bill.sh」のパス') | |
obj = JSON.parse(result) | |
bill = '・・・$'+obj["Maximum"] | |
msg.send(bill) |
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/bash | |
aws cloudwatch --region us-east-1 get-metric-statistics \ | |
--namespace "AWS/Billing" \ | |
--metric-name "EstimatedCharges" \ | |
--dimensions "[{\"Value\":\"AmazonEC2\",\"Name\":\"ServiceName\"},{\"Value\":\"USD\",\"Name\":\"Currency\"}]" \ | |
--period 60 \ | |
--start-time `date -u -d '3 hours ago' +%Y-%m-%dT%TZ` \ | |
--end-time `date -u +%Y-%m-%dT%TZ` \ | |
--statistics "Maximum" \ | |
| jq '.Datapoints | sort_by(.Timestamp) | reverse | .[0]' |
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
{ | |
"Timestamp": "2015-05-25T01:08:00Z", | |
"Maximum": 10.25, | |
"Unit": "None" | |
} | |
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
npm install --save-dev execsyncs | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment