AWS SDK for Ruby profile change & assume role

Since it was difficult to understand the profile specification of credentials and the assume role method in AWS SDK for Ruby, it is described.

↓ profile is the one created as below with aws-cli

$ aws configure --profile hoge

profile specification

Just pass it as a Client argument Example: 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,
  # ...
)

Recommended Posts

AWS SDK for Ruby profile change & assume role
Get S3 object size with AWS SDK for Ruby
AWS SDK for Java 1.11.x and 2.x
Credentials referenced by the AWS SDK for Java by default