AWS Assume Role Script

Ripon Banik
2 min readJun 12, 2019

Have access to AWS in different account using Bash/Poweshell

Those who working in multi account and hybrid environment (both AWS and On-prem) would know that it is not possible to just to set profile like ec2 for on-prem and have it generate the AWS credential dynamically or it is still require to assume role in other accounts.

There are tools which does that work for you, but there could be some dependency which is another thing to maintain and/or you want to just use commands in your script which is transparent and simple.

First thing first, you need to create a user with access key and secret key in the source account, role in the destination account and optionally set mfa. Also install aws cli.

After the access key and secret key is created, set the default profile as per the guidence below -

Now the scripts,

  1. Bash without mfa — it will also create a new profile under ~/.aws/credentials

--

--

Ripon Banik

A Cloud and DevSecOps Engineer passionate about simplification of technology and make it consumable.