Created
December 2, 2010 04:55
-
-
Save bryanjswift/724795 to your computer and use it in GitHub Desktop.
Print out useful information about running ec2 instances
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
#!/usr/bin/env ruby | |
# | |
# This ruby script will print out useful information about running ec2 | |
# instances | |
# | |
# Reads AWS access and secret keys from environment variables | |
# | |
# Requires the amazon-ec2 gem (gem install amazon-ec2) | |
# | |
# Author: Bryan J Swift (bryan.j.swift@gmail.com) | |
require 'rubygems' | |
require 'AWS' | |
ACCESS_KEY_ID = ENV['EC2_ACCESS'] | |
SECRET_ACCESS_KEY = ENV['EC2_SECRET'] | |
ec2 = AWS::EC2::Base.new(:access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY) | |
ec2.describe_instances.reservationSet.item.each do |instance| | |
terminated = instance.instancesSet.item[0].instanceState.name == "terminated" | |
dns = instance.instancesSet.item[0]['dnsName'] | |
instanceId = instance.instancesSet.item[0]['instanceId'] | |
name = "'" + instance.instancesSet.item[0].tagSet.item.reject { |t| t.key != "Name" }[0].value + "'" | |
vals = [name, instanceId, dns] | |
if !terminated then | |
puts vals.join(" -- ") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment