How to Get your Default Profile with AWS CLI

avatar

Borislav Hadzhiev

Thu Sep 30 20212 min read

Get your Default Profile with AWS CLI #

In order to see which your default AWS CLI profile is, run the aws configure list command. The command shows the name of the default profile, the profile's security credentials and region.

shell
aws configure list

get default profile aws cli

In the example above, we can see that the default profile's name is tester.

The configure list command also shows where the name of the default profile is set.

In this case the name of the default profile is set using the AWS_PROFILE environment variable, which has higher precedence than the settings in the credentials file.

You can find the Access Key ID and Secret Access Key of the profile in the credentials file:

shell
# on Linux and macOS ~/.aws/credentials # on Windows C:\Users\USERNAME\.aws\credentials

The region and CLI output format for the profile are stored in the config file in the same directory:

shell
# on Linux and macOS ~/.aws/config # on Windows C:\Users\USERNAME\.aws\config

When an AWS CLI command is invoked it looks for your credentials in:

  1. Command line options - have the highest precedence and override any environment variables or configuration stored in config and credentials files.

    The command line options are: --region, --profile and --output.

  2. Environment variables on the machine - have higher precedence than the config and credentials files but get overridden by command line options.

    The environment variables are: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_OUTPUT, AWS_DEFAULT_REGION, AWS_PROFILE.

  3. The config and credentials files on your machine - have the lowest precedence - lower than environment variables and command line options.

If you are unsure where your CLI is pulling your credentials or configuration settings from, look at the Location column when calling aws configure list.

If the command's output shows that the Type is set to env and the Location is an environment variable, then it gets higher precedence than the values you've specified in your credentials file.

get default profile location

To verify whether an Environment variable is set on your machine, run the echo command that corresponds to your operating system:

shell
# Linux and macOS echo $AWS_PROFILE # on Windows with CMD echo %AWS_PROFILE% # on Windows with PowerShell echo $Env:AWS_PROFILE
You can always override the value of the default profile for one off commands by setting the --profile parameter, e.g. aws s3 ls --profile tester.

If you want to change your default profile, check out my other article - Set your Default Profile's Name in AWS CLI .

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