AWS_PROFILE not working with aws cli

Just re-state in another words and clean commands:

Run set | grep AWS, if you see any credentials there then AWS_PROFILE will be ignored

If you set the variable just as

AWS_PROFILE=boo

it won't work. Export it instead:

export AWS_PROFILE=boo


As per this link: AWS CLI environment variables Precedence

If AWS_PROFILE environment variable is set and the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are set, then the credentials provided by AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY will override the credentials located in the profile provided by AWS_PROFILE.

You have to unset both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY and set AWS_PROFILE instead then it should work correctly.

unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
export AWS_PROFILE=[profile-name-here]

This looks like a bug to me.

Check my setup when I have nothing set for profile:

15278-gmcdaid:~ gmcdaid$ aws configure list
  Name                    Value             Type    Location
  ----                    -----             ----    --------
profile                <not set>             None    None

Now, set the env var:

15278-gmcdaid:~ gmcdaid$ export AWS_PROFILE=foo

Check setup again:

15278-gmcdaid:~ gmcdaid$ aws configure list
  Name                    Value             Type    Location
  ----                    -----             ----    --------
profile                  foo           manual    --profile

You can see that when AWS_PROFILE is set, the cli is set to use the manual switch for the profile, not the env var.

I installed the aws-cli around the same time you make this post.


I was only setting the AWS_PROFILE as a shell variable and not as a environment variable. After setting is as an environment variable everything worked as expected.

Tags:

Aws Cli