3
3

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.

AWS SDK for Ruby v2を使ってみる

Last updated at Posted at 2015-02-17

そろそろ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を使うべきなのか。

3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?