hubot-aws
Version:
Hubot masters aws commands
41 lines (36 loc) • 1.42 kB
text/coffeescript
aws = require('../../aws').aws()
ec2 = new aws.EC2()
module.exports = (robot) ->
robot.respond /ec2 associate (.*) to (.*)/i, (msg) ->
msg.send 'Working on it...'
params = {
InstanceId: msg.match[2]
}
if msg.match[1].split('.').length == 4
params.PublicIp = msg.match[1]
if msg.match[1].match /eipalloc/i
params.AllocationId = msg.match[1]
if msg.match[2].match(/^i-[a-zA-Z0-9].*/i)
ec2.describeAddresses {
AllocationIds: [params.AllocationId]
}, (err, addresses) ->
if(err)
msg.send err
else
ec2.associateAddress params, (err, response) ->
if err
msg.send err
else
url = "https://console.aws.amazon.com/ec2/v2/home?region=" + process.env.HUBOT_AWS_REGION + "#Instances:instanceId=" + params.InstanceId + ";sort=desc:tag:Name"
msg.send "I attached " + params.PublicIp + " to the instance " + params.InstanceId + ". Association Id is " + response.AssociationId + "."
msg.send url
else
msg.send "I'm not sure I understood what you wanted me to do."