If you’re like me, used multiple aws accounts on our development environment but like to switch profile like browser tab, you could do it easily.
No more --profile USERNAME in every aws commands.
Getting started (skip if you have one already)
Right from the start you need to config globally like git --config. For the best practice & security, please don’t use root account access key, just create an admin user with full access could do the job easily.
aws configure
After that you can identify your default account by
aws configure list // list in table
aws configure list-profiles // list profile name
All credential & config are store as text file under ~/.aws in Unix and %USERPROFILE%\.aws\credentials in Windows.
Name Value Type Location
---- ----- ---- --------
[default]
aws_access_key_id = YOUR_ACCESS_KEY
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY
Multiple profiles
If you’re fancy creating IAM user from CLI
aws iam create-user --user-name YOURNAME
aws iam create-access-key --user-name YOURNAME // save access & secret keys
aws configure --profile YOURNAME // follow along
Now You can list all your profiles again, You’ll see default and YOURNAME (your given user name).
aws configure list-profiles // list profile names
To switch profile -
export AWS_PROFILE=YOURNAME // to run as newly created user
set AWS_PROFILE=YOURNAME // in Windows
You can check your current profile by
aws sts get-caller-identity
You can clear that env by
unset AWS_PROFILE
You can checkout as default user again
export AWS_PROFILE=default // to run as default admin user
For more information please refer to official name profiles.