Created
March 1, 2015 13:52
-
-
Save Atalanta/5c4a8f3bef4b41b3e233 to your computer and use it in GitHub Desktop.
Network Map
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
require 'awesome_print' | |
require 'aws-sdk-core' | |
ec2 = Aws.ec2 | |
subnets = [] | |
ec2.describe_subnets.subnets.each { |s| subnets << s } | |
list = subnets.each_with_object({}) { |s,h| h[s.subnet_id] = s.cidr_block} | |
list.each do |subnet, cidr| | |
puts "Subnet: #{subnet} - #{cidr}" | |
images = [] | |
ec2.describe_instances(filters: [{name: 'subnet-id', values: [subnet] }]).each { |p| images << p.reservations } | |
puts "Instances using this subnet: #{images.flatten.size}" | |
if images.flatten.size > 0 | |
ap images.flatten.each_with_object({}) { |i,h| h[i.instances.first.instance_id] = i.instances.first.security_groups.first.group_name} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment