Skip to content

Instantly share code, notes, and snippets.

@srockstyle
Created September 25, 2014 02:05
Show Gist options
  • Select an option

  • Save srockstyle/8ef23a5134a3eee8d207 to your computer and use it in GitHub Desktop.

Select an option

Save srockstyle/8ef23a5134a3eee8d207 to your computer and use it in GitHub Desktop.
AWS-SDK for RubyからELB直下のインスタンスのpublic DNSを一括取得するには ref: http://qiita.com/srockstyle/items/7b72a56bc0ac02953164
#!/usr/bin/ruby
require "aws-sdk"
require "pp"
AWS.config(
access_key_id: '******',
secret_access_key: '******',
ec2_endpoint: '[環境に合わせてください]',
elb_endpoint: '[環境にあわせてください]'
)
elb = AWS::ELB.new.load_balancers['[自分のELB名]']
instances = elb.instances.select {|i| i.exists? && i.status == :running}.map(&:dns_name)
pp instances
[ "ec2-**-***-***-**.ap-southeast-1.compute.amazonaws.com",
"ec2-**-***-***-**.ap-southeast-1.compute.amazonaws.com",
"ec2-**-***-***-**.ap-southeast-1.compute.amazonaws.com",
"ec2-**-***-***-**.ap-southeast-1.compute.amazonaws.com"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment