Skip to content

Instantly share code, notes, and snippets.

@jhmartin
Created January 23, 2017 22:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhmartin/c669c902c59d2dc33741d42b4e20fbf7 to your computer and use it in GitHub Desktop.
Save jhmartin/c669c902c59d2dc33741d42b4e20fbf7 to your computer and use it in GitHub Desktop.
How to use cross-account roles in AWS RUby SDK
require 'aws-sdk'
role_credentials = Aws::AssumeRoleCredentials.new(
client: Aws::STS::Client.new(),
role_arn: "arn:aws:iam::123:role/cross-account-role",
role_session_name: ENV['USER'],
serial_number: "arn:aws:iam::123:mfa/usernamehere",
token_code: ARGV[0]
)
cw = Aws::CloudWatch::Client.new(
credentials: role_credentials
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment