If you are working with multiple AWS accounts, you can easily switch between your accounts by creating multiple profiles on the CLI.
Get list of AWS profiles
aws configure list-profiles
. By default, there will be onedefault
profileTo add a new profile, you will first need to generate an
access_key_id
and asecret_access_key
.Profiles are stored under the config and credentials files. You can configure additional profiles by adding entries to the files. In this case, we will add a new profile
user1
:
$ vim ~/.aws/config
[default]
region=us-west-2
output=json
[profile user1] // Include the prefix "profile" only when
configuring a named profile in the config file
region=us-east-1
output=json
$ vim ~/.aws/credentials
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[user1] // Do not use the prefix "profile"
aws_access_key_id=YOUR_ACCESS_KEY
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
- Verify that the profile is successfully added by
aws configure list-profiles
. You should now see 2 profiles:
default
user1
To switch between different AWS accounts, set the AWS_profile environment variable at the command line via
export AWS_PROFILE=profile_name
. Setting the env variable changes the default profile until the end of your shell session or until you set the variable to a different value.Use
aws configure list
to list your current profile.
For documentation to named profiles, see guide here.
Top comments (4)
how can i make user 1 the default user
Life saver.
Short, direct and powerful article
For windows users, use:
set AWS_PROFILE=profile_name
instead
thanks a million