Skip to content

Instantly share code, notes, and snippets.

@thattommyhall
Created February 27, 2012 16:36
Show Gist options
  • Save thattommyhall/1925229 to your computer and use it in GitHub Desktop.
Save thattommyhall/1925229 to your computer and use it in GitHub Desktop.
List servers in all EC2 regions
require 'fog'
AWS = Fog::Compute.new(:provider => 'AWS')
REGIONS = AWS.describe_regions.body["regionInfo"].map {|region| region["regionName"]}
COMPUTE = {}
REGIONS.each do |region|
COMPUTE.merge!(region => Fog::Compute.new({:provider => 'AWS', :region=>region}))
end
COMPUTE.each_pair do |region,connection|
puts "***#{region}***"
availability_zones = connection.describe_availability_zones.body["availabilityZoneInfo"].map{|zone| zone["zoneName"]}
availability_zones.each do |zone|
puts "**#{zone}**"
puts connection.servers.select{|server| server.availability_zone == zone}.map{|server| server.tags["Name"]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment