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
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,
# ...
)