Sometimes one may have multiple sets of credentials to use with AWS, perhaps both personal and work accounts, accounts for multiple projects, etc.

That could cause confusion when using the AWS CLI, but there is a simple way to manage different profiles.

Default credentials and config files will resemble the following.

.aws/credentials [Locations vary depending on OS.]

[default]
aws_access_key_id = (key_id)
aws_secret_access_key = (secret)

.aws/config

[default]
region=us-east-1
output=json

To use additional profiles, modify the files as shown:

.aws/credentials

[default]
aws_access_key_id = (key_id)
aws_secret_access_key = (secret)

[work_user]
aws_access_key_id = (key_id)
aws_secret_access_key = (secret)

.aws/config

[default]
region=us-east-1
output=json

[profile work_user]
region=us-west-1
output=json

Now AWS CLI commands may be run with the --profile option:

$ aws s3 ls --profile work_user

There is also an environment variable AWS_PROFILE which may be set to specify a default.