Skip to content

Instantly share code, notes, and snippets.

@king-panda
Last active August 29, 2015 14:21
Show Gist options
  • Save king-panda/8e40cca844a11e2beacf to your computer and use it in GitHub Desktop.
Save king-panda/8e40cca844a11e2beacf to your computer and use it in GitHub Desktop.
【Hubot】AWSの利用料金を聞くと答えてくれるようにした ref: http://qiita.com/kingpanda/items/aa1b24ffd12dd81f1ab2
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)
#!/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]'
{
"Timestamp": "2015-05-25T01:08:00Z",
"Maximum": 10.25,
"Unit": "None"
}
npm install --save-dev execsyncs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment