LoginSignup
0
0

More than 3 years have passed since last update.

AWS SDK for Ruby profile変更 & assume role

Posted at

AWS SDK for Rubyにてcredentialsのprofile指定とassume role方法についてわかりづらかったので記載

↓profileはaws-cliで下記のように作成した際のもの

$ aws configure --profile hoge

profile指定

Clientの引数に渡すだけ
例:EC2

ec2 = Aws::EC2::Client.new(
  profile: "hoge",
  # ...
)

assume role

require 'aws-sdk-core'
require 'aws-sdk-ec2'

role_credentials = Aws::AssumeRoleCredentials.new(
  client: Aws::STS::Client.new(opts),
  role_arn: "arn:aws:iam::xxxxxxxxxxxx:role/hoge_role",
  role_session_name: hoge
)

ec2 = Aws::EC2::Client.new(
  credentials: role_credentials,
  # ...
)
0
0
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
0
0