Last active
December 14, 2015 09:19
-
-
Save pixelpogo/5064183 to your computer and use it in GitHub Desktop.
Get a list of all your EC2 instances in all AWS regions
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 "rubygems" | |
require "aws-sdk" | |
require "hirb" | |
extend Hirb::Console | |
ec2 = AWS::EC2.new( | |
:access_key_id => 'YOUR_ACCESS_KEY_ID', | |
:secret_access_key => 'YOUR_SECRET_ACCESS_KEY') | |
instances = [] | |
ec2.regions.each do |region| | |
print "\r\e[0KLooking for instances in #{region.name}..." | |
$stdout.flush | |
region.instances.each do |i| | |
instances << { | |
:id => i.id, | |
:ip => i.ip_address, | |
:private_ip => i.private_ip_address, | |
:dns => i.dns_name, | |
:status => i.status, | |
:region => region.name, | |
:type => i.instance_type } | |
end | |
end | |
print "\r\e[0K" | |
$stdout.flush | |
table instances |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment