Have several AWS accounts that you access through delegation? Want a id/key combo for each one? Need to use MFA? But want to use the cli?

It can get frustrating managing so many accounts. If you have one (or even more) 'master' account that you assume roles in other accounts then this script will handle generating profiles and temporary session credentials, and keeping your MFA logins to a minimum.


Install with

$ gem install aws_role_creds


Create a YAML file to manage your profiles, and MFA device, at ~/.aws/config.yaml

  - name:
    mfa_arn: (optional)
    region: (optional)
  - name:
    region: (optional)
    default: default profile to use

  - name:
    mfa_serial: (optional)
    region: (optional)
    role_arn: (optional)
    source_profile: (optional)
    external_id: (optional)
    role_session_name: (optional)

Run aws_role_creds and it will get credentials for your default accounts. It will then use these credentials to Assume Roles and get credentials for each of your profiles.

Default accounts get creds lasting 24 hours, and assumed role profiles can last an hour. If your credentials expire, run the script again and it will refresh them. It will ask for you MFA if its required, i.e. your session credentials have expired.

Any exists items are added to the credentials and config file as is, no role stuff will happen to them. These correspond to the names here.


After checking out the repo, run bin/setup to install dependencies.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to


Bug reports and pull requests are welcome on GitHub at


The gem is available as open source under the terms of the MIT License.