97

When I give the command aws config list, I get the following output for the default profile:

      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None

However, when I give the command for a named profile, I get a profile name

$ aws configure list --profile MyProfile
      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                MyProfile           manual    --profile

I have tried aws configure set profile Default to name the default profile as Default by reading the 'set' CLI command, I also tried aws configure set StoreAs Default because I thought that's what's the variable is named after I read this page. I want to do this because I want have two profiles and I want to switch between profiles using the AWS_DEFAULT_PROFILE environment variable.

TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53

5 Answers5

113

I have multiple profiles too, I use AWS_DEFAULT_PROFILE to switch back and forth. However, I've named each profile something descriptive, like aws-engineering and aws-production. Then, I can use set AWS_DEFAULT_PROFILE=aws-engineering and I'm good to go.

I have no DEFAULT profile specified in my ~/.aws/config, this was intentional so that I always explicitly have to choose which environment I'm working on.

tuomastik
  • 4,559
  • 5
  • 36
  • 48
ijustneedanswers
  • 1,146
  • 1
  • 8
  • 5
  • 11
    Not having a default is a clever thing to do! Avoids (potentially costly) accidents due using the wrong profile. – Marco Roy Aug 26 '20 at 19:22
  • If you are using bash and want that extra bit of security you could also prefix your command with a space so that bash won't store it in the command history log (https://stackoverflow.com/a/29188490/507654) – hbobenicio Sep 02 '22 at 19:29
  • 2
    This answer is outdated. [Environment variables to configure the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) does not mention `AWS_DEFAULT_PROFILE`. Instead, use `AWS_PROFILE`. – Wolfgang Kuehn May 14 '23 at 08:20
66

Setting the AWS_DEFAULT_PROFILE environment variable at the command line should specify the profile.

See: Can I specify a default AWS configuration profile?

For example:

Linux, macOS, or Unix

export AWS_DEFAULT_PROFILE=user2

Note: To unset, run: unset AWS_DEFAULT_PROFILE.

To make the change persistent, add above line into your ~/.bashrc user's file.

Note: You can also use AWS_PROFILE. See: Named Profiles.

Windows

set AWS_DEFAULT_PROFILE=user2

Source: User Guide » Configuring the AWS CLI » Named Profiles.

See also: A New and Standardized Way to Manage Credentials in the AWS SDKs.

kenorb
  • 155,785
  • 88
  • 678
  • 743
12

You just switch to the profile you want (for ex: in Linux use: export AWS_DEFAULT_PROFILE=MyProfile) and then switch back to the default profile using export AWS_DEFAULT_PROFILE=default. 'default' is the profile name given to your first profile when you create it.

TheRookierLearner
  • 3,643
  • 8
  • 35
  • 53
10

in Windows if you want to make sure the change of profile persists in new command line session better to use setx

setx AWS_DEFAULT_PROFILE profle_name

Remember to to close the command prompt and open a new one

Subrata Fouzdar
  • 724
  • 5
  • 17
6

If you want to set up your own profile as a default one then you should consider making changes to your shell's startup script.

For Powershell, this is how you can do it.

$Env:AWS_PROFILE="admin"

here the profile name is admin .

In Linux and macOS you can do something like this.

export AWS_PROFILE=admin

if changes persist then everything is good otherwise make changes to your ~/.bashrc or ~/.zshrc.

DataCrusade1999
  • 492
  • 4
  • 4
  • It's works on PowerShell command. To ensure you could use `aws configure list` the response should be match with your profile. – YGautomo Nov 05 '22 at 09:18