32

I have the aws cli installed on my macbook. I updated the version last week and since then it seems like it ignores the AWS_PROFILE environment variable? Has anyone encountered this? I have to add --profile to every statement now to make it go towards the profile I prefer.

Does anyone know what could be wrong or how I should troubleshoot it?

KOT
  • 1,986
  • 3
  • 21
  • 35

4 Answers4

62

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]
Mina Luke
  • 2,056
  • 1
  • 20
  • 22
16

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.

Garreth McDaid
  • 2,427
  • 22
  • 34
  • 1
    Interesting, but it still sets the profile to foo, so it works for you anyway? – KOT May 08 '18 at 11:35
  • I opened an issue with the developers. Seems AWS_PROFILE is ignored if AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID are set. https://github.com/aws/aws-cli/issues/3304 – Garreth McDaid May 09 '18 at 09:45
  • 1
    Mine is working now :) I doublechecked my variables and I only set my variable as a shell variable and not as an environment variable. When I did that it started working – KOT May 09 '18 at 10:48
  • 2
    Still not working for me, with either Env of Shell vars. Could you provide any more detail or examples? – Garreth McDaid May 16 '18 at 11:26
  • I didn't do much. I am using fish so I type: "set -xg AWS_PROFILE myprofile". Optionally use -U as well to set it everywhere. Then "env" displays the variable and aws configure list works as expected – KOT May 23 '18 at 08:51
11

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.

KOT
  • 1,986
  • 3
  • 21
  • 35
5

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

Putnik
  • 5,925
  • 7
  • 38
  • 58