Skip to content

Instantly share code, notes, and snippets.

@scottb
Last active February 25, 2019 19:32
Show Gist options
  • Save scottb/9b86a2030e90108a8d2c7a2c4aa7c2e9 to your computer and use it in GitHub Desktop.
Save scottb/9b86a2030e90108a8d2c7a2c4aa7c2e9 to your computer and use it in GitHub Desktop.
Generate the necessary envariables to authenticate a shell window to AWS when an MFA token is in use
require 'aws-sdk'
duration = 24 * 60 * 60
creds = Aws::STS::Client.new.get_session_token(duration_seconds: duration, serial_number: ARGV[0], token_code: ARGV[1]).credentials
puts "export AWS_ACCESS_KEY_ID=#{creds.access_key_id}"
puts "export AWS_SECRET_ACCESS_KEY=#{creds.secret_access_key}"
puts "export AWS_SESSION_TOKEN=#{creds.session_token}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment