#!/usr/bin/env ruby require 'rubygems' require 'EC2' #rescue `gem install -y grempe-amazon-ec2` aws_keys = {} aws_keys = YAML::load( File.open('/etc/poolparty/aws_keys.yml') ) rescue 'No aws_keys.yml file. Will try to use enviornment variables' ACCESS_KEY_ID = aws_keys[:access_key] || ENV['AMAZON_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY'] SECRET_ACCESS_KEY = aws_keys[:secret_access_key] || ENV['AMAZON_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_ACCESS_KEY'] if ENV['EC2_URL'] ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY, :server => URI.parse(ENV['EC2_URL']).host ) else # default server is US ec2.amazonaws.com ec2 = EC2::Base.new( :access_key_id => ACCESS_KEY_ID, :secret_access_key => SECRET_ACCESS_KEY ) end response = ec2.describe_instances public_dns_names = response.reservationSet.item.first.instancesSet.item.collect do |instance| p instance instance.dnsName if instance.instanceState.name == 'running' end.compact puts public_dns_names.join("\t")