Set your Default Profile's Name in AWS CLI

avatar
Borislav Hadzhiev

Last updated: Feb 26, 2024
2 min

banner

# Set the Default Profile's Name in AWS CLI

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:

~/.aws/credentials
[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.

shell
# 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.

The only way to override the 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.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.