LoginSignup
3

More than 5 years have passed since last update.

posted at

updated at

AWS SDK for Ruby v2を使ってみる

そろそろv2にも慣れておこうと、ドキュメント(※)見ながらちまちま触ってみたのでメモ。
(※) http://docs.aws.amazon.com/sdkforruby/api/frames.html

windows以外のEC2インスタンス名を列挙するプログラム。

require 'aws-sdk-core'

client = Aws::EC2::Client.new(
   region: config['Region'],
   access_key_id: config['AccessKey'],
   secret_access_key: config['SecretKey']
)

instance_name       = ""

r = client.describe_instances
r.each_page {|page|
  page.reservations.each { |reservation|
    info = reservation.instances[0]

    is_linux = (info[:platform] == nil)
    unless is_linux
      next
    end

    info[:tags].each { |tag|
      if tag[:key] == "Name"
        instance_name = tag[:value]
      end
    }

    p instance_name
  }
}

自身のコーディング力不足もあるが、イマイチみにくい。。。
aws-sdk-resourcesを使うべきなのか。

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
What you can do with signing up
3