LoginSignup
2
3

More than 5 years have passed since last update.

aws ruby v2について調べてみた

Last updated at Posted at 2015-11-12

ec2について

公式サイト:http://docs.aws.amazon.com/sdkforruby/api/Aws/EC2/Client.html
まず、ec2を触るオブジェクトをインスタンス化する必要があるのだか、
それは、以下のようにする。

ec2 = Aws::EC2::Client.new(
  region: region_name,
  credentials: credentials,
  # ...
)

regionはリージョン名を設定し、credentialsは認証情報を設定する。

regionを設定するには2つ方法がある。

  • ENV['AWS_REGION']
  • Aws.config[:region]

region名は、http://docs.aws.amazon.com/ja_jp/general/latest/gr/rande.html
を参考にしてほしい。
一応、載せておく。

Amazon API Gateway

リージョン名 リージョン エンドポイント プロトコル
アジアパシフィック(東京) ap-northeast-1 apigateway.ap-northeast-1.amazonaws.com HTTPS
欧州(アイルランド) eu-west-1 apigateway.eu-west-1.amazonaws.com HTTPS
US East (N. Virginia) us-east-1 apigateway.us-east-1.amazonaws.com HTTPS
米国西部(オレゴン) us-west-2 apigateway.us-west-2.amazonaws.com HTTPS

credentialsを設定方法

  • ENV['AWS_ACCESS_KEY_ID'] and ENV['AWS_SECRET_ACCESS_KEY'] を使用できるように設定
  • Aws.config[:credentials] に記述
  • ~/.aws/credentials に記述
  • EC2 からsdkを使う

ec2Clientオブジェクトに何らかのメソッドを使うと、情報が取得出来たり、ec2を起動したりすることができる。

メソッド名は、[動詞]_[対象の名称] という感じで綺麗に整理されている。

例えば、
describe.... というメソッドを使うと、ec2に関する情報が取得できる。

#describe_reserved_instances(options = {}) を使うと、現在リソースを借りているインスタンスに関する情報が取得出来たりする。

resp = client.describe_reserved_instances({
  dry_run: true,
  reserved_instances_ids: ["String"],
  filters: [
    {
      name: "String",
      values: ["String"],
    },
  ],
  offering_type: "Heavy Utilization", # accepts Heavy Utilization, Medium Utilization, Light Utilization, No Upfront, Partial Upfront, All Upfront
})

のように、フィルターの条件など指定することができる。

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