用于ec2列表的aws-sdk-v2

时间:2015-11-25 19:29:30

标签: ruby scripting aws-sdk

这是正确的方法吗?如果还有其他更好的方法可以帮忙吗?

#! /usr/bin/ruby
require 'aws-sdk'

client = Aws::EC2::Client.new(region: 'us-west-2')
resp = client.describe_instances
resp.reservations.each do |node, num = 0|
  puts "#{node.instances[num].instance_id}"
end

1 个答案:

答案 0 :(得分:0)

  credential = {
                 access_key_id: 'xxxxxxxxxxxxxxxxxxxx',
                 secret_access_key: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
                 region: 'us-west-2'
               }

  Aws.config.update aws_credential

  Aws::EC2::Client.new.describe_instances.reservations.each do |instance|
    p instance[0].instance_id
  end