Set your Default Profile's Name in AWS CLI

avatar

Borislav Hadzhiev

Fri Sep 24 20211 min read

banner

Photo by Erik Mclean

Set the Default Profile's Name in AWS CLI #

In order 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 executed 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 # 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.

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee