Created
January 29, 2016 19:53
-
-
Save filipenf/bd403c1bb9f928a69aa1 to your computer and use it in GitHub Desktop.
Simple hubot script to get information about an instance
This file contains hidden or 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
| util = require 'util' | |
| init_aws = () -> | |
| aws = require 'aws-sdk' | |
| return aws | |
| module.exports = (robot) -> | |
| robot.respond /ec2 get-instance (.*)$/i, (msg) -> | |
| ins_id = msg.match[1].trim() | |
| if ins_id.match /i-.*/ | |
| params = { InstanceIds: [ins_id] } | |
| else | |
| params = { Filters: [ { Name: "private-ip-address", Values: [ ins_id ] } ] } | |
| msg_txt = "Fetching #{ins_id}" | |
| msg.send msg_txt | |
| aws = init_aws() | |
| aws.config.region="us-east-1" | |
| ec2 = new aws.EC2({apiVersion: '2014-10-01'}) | |
| ec2.describeInstances (params), (err, res) -> | |
| if err | |
| msg.send "DescribeInstancesError: #{err}" | |
| else | |
| if res.Reservations.length == 0 | |
| msg.send "Nothing found for #{ins_id}" | |
| else | |
| msg.send util.inspect(res.Reservations[0].Instances[0], false, null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment