Skip to content

Instantly share code, notes, and snippets.

@fredjean
Created August 16, 2012 16:43
Show Gist options
  • Save fredjean/3371568 to your computer and use it in GitHub Desktop.
Save fredjean/3371568 to your computer and use it in GitHub Desktop.
require 'right_aws'
def instances_from_ec2(load_balancer = nil)
load_balancer ||= aws_load_balancer
payload = elb.describe_load_balancers(load_balancer)
instances = ec2.describe_instances payload.first[:instances]
instances.collect{|instance| instance[:dns_name] if (instance[:aws_state] == 'running')}
end
def elb
@elb ||= RightAws::ElbInterface.new(aws_access_key_id, aws_secret_access_key, :region => 'us-west-1')
end
def ec2
@ec2 ||= RightAws::Ec2.new(aws_access_key_id, aws_secret_access_key, :region => 'us-west-1')
end
role :web do
instances_from_ec2
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment