Install AWS SDK for Ruby
AWS SDK for Rubyのインストール
既にRubyの環境が存在する場合は、以下のようにコマンド一行で
sdkをインストールできます。
$ sudo gem install aws-sdk
[sudo] password for username:
Fetching: jmespath-1.1.3.gem (100%)
Successfully installed jmeshpath-1.1.3
Fetching: aws-sdk-core-2.2.8.gem (100%)
Successfully installed aws-sdk-core-2.2.8
Fetching: aws-sdk-resources-2.2.8.gem (100%)
Successfully installed aws-sdk-resources-2.2.8
Fetching: aws-sdk-2.2.8.gem (100%)
Successfully installed for aws-sdk-2.2.8
Parsing documentation for jmespath-1.1.3
Installing ri documentation for jmespath-1.1.3
Parsing documentation for aws-sdk-core-2.2.8
Installing ri documentation for aws-sdk-core-2.2.8
Parsing documentation for aws-sdk-resources-2.2.8
Installing ri documentation for aws-sdk-resources-2.2.8
Parsing documentation for aws-sdk-2.2.8
Installing ri documentation for aws-sdk-2.2.8
Done installing documentation for jmespath, aws-sdk-core, aws-sdk-resources, aws-sdk after 4 seconds
4 gems installed
AWS SDK for Ruby利用開始までの手順
アクセスキーとシークレットキーを
file:/home/username/.aws/credentialsに格納し、
各クライアントもしくはリソースAPIを利用します。
file:/home/username/.aws/credentials
[default]
aws_access_key_id = ABCDE12345
aws_secret_access_key = ABCDE12345
[app01]
aws_access_key_id = ABCDE12345
aws_secret_access_key = ABCDE12345
EC2 初期化例
require 'aws-sdk-core' # for EC2::Client
require 'aws-sdk-resources' # for EC2::Resource
creds = Aws::SharedCredentials.new(
profile_name: 'default',
)
# client constructors
ec2cli = Aws::EC2:Client.new(
region: "ap-northeast-1", # or export AWS_REGION=ap-northeast-1
credentials: creds
)
# resource constructors
ec2res = Aws::EC2::Resource.new(
region: "ap-northeast-1",
credentials: creds
)