Last updated: Feb 26, 2024
Reading time·2 min

To set the name for the default AWS CLI profile, set the AWS_PROFILE
environment variable to the name of the profile stored in your credentials and
config files, e.g. admin for a named profile, or default for the default
profile.
For example, if my AWS credentials file consists of the default and admin
profiles:
[default] aws_access_key_id=MY_ACCESS_KEY_ID aws_secret_access_key=MY_SECRET_ACCESS_KEY [admin] aws_access_key_id=MY_OTHER_ACCESS_KEY_ID aws_secret_access_key=MY_OTHER_SECRET_ACCESS_KEY
And I set the AWS_PROFILE environment variable to admin, then any AWS CLI
command I run, without explicitly setting the --profile parameter, will be run
with the admin profile's credentials.
How you set the AWS_PROFILE environment variable depends on your operating
system.
# Linux and MacOS export AWS_PROFILE=admin # Windows Command Prompt setx AWS_PROFILE admin # Windows with PowerShell $Env:AWS_PROFILE="admin"
To make the environment variable persist on Linux and MacOS, add the
export AWS_PROFILE=your_profile line to your shell's startup script, e.g.
~/.bashrc.
If the AWS_PROFILE environment variable is set, it has higher precedence and
overrides the default profile you've stored in your credentials and config
files.
AWS_PROFILE environment variable is to pass the --profile parameter to the specific AWS CLI command.I've also written an article on how to get your default profile with the AWS CLI.
You can learn more about the related topics by checking out the following tutorials: