Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
43 lines (35 sloc) 996 Bytes
# Output all ELBs and their corresponding instances
# Written by Jared Williams <thisis@jared.nyc>
#
# If you have any questions or comments, heres the ways to reach me:
# email: thisis@jared.nyc
# slack: https://devopschat.co signing up is free and my username is @jaredwilliams
# github: @jaredmichaelwilliams
# reddit: jaredw
#
# Instructions
# 1. Install the following gems: json, aws-sdk (version 2 only!)
# 2. Run and watch!
#
require 'rubygems'
require 'json'
require 'aws-sdk'
ec2 = AWS::EC2.new
aws_elb = AWS::ELB.new
instances = {}
elbs = {}
parent = {}
aws_elb.load_balancers.each do |elb|
puts elb.name
elbs[elb.name] = Array.new
elb.instances.each do |instance|
elbs[elb.name].push(instance.tags.Name)
if (instances[instance.tags.Name].nil?)
instances[instance.tags.Name] = Array.new
end
instances[instance.tags.Name].push(elb.name)
end
end
parent['elb-to-instance'] = elbs
parent['instance-to-elb'] = instances
puts JSON.pretty_generate(parent)