6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby を使って、特定の ELB 下の EC2 インスタンスの IPアドレスを取得する

Last updated at Posted at 2014-07-23
require "aws-sdk"
def get_ec2_instances elb_name, region
  client = AWS::ELB.new region: region,
  access_key_id: ENV["AWS_ACCESS_KEY_ID"],
  secret_access_key: ENV["AWS_SECRET_ACCESS_KEY"]
  elb = client.load_balancers.find{|lb| lb.name == elb_name}
  Array.new.tap do |ip_addrs|
    elb.instances.each do |instance|
    ip_addrs << instance.private_ip_address
  end
end

ip_addrs = get_ec2_instances "YOUR_ELB_NAME", "YOUR_REGION"
p ip_addrs
6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?