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
More than 5 years have passed since last update.
Ruby を使って、特定の ELB 下の EC2 インスタンスの IPアドレスを取得する
Last updated at Posted at 2014-07-23
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme