Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS_PROFILE not working with aws cli

Tags:

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?

like image 522
KTrum Avatar asked Apr 23 '18 18:04

KTrum


People also ask

What is Aws_profile environment variable?

If defined, this environment variable overrides the value for the profile setting cli_pager . AWS_PROFILE. Specifies the name of the AWS CLI profile with the credentials and options to use. This can be the name of a profile stored in a credentials or config file, or the value default to use the default profile.

How do I create a named profile in AWS CLI?

You can configure a named profile using the --profile argument. If your config file does not exist (the default location is ~/. aws/config ), the AWS CLI will create it for you. To keep an existing value, hit enter when prompted for the value.

Where does AWS CLI look for credentials?

The credentials file is located at ~/. aws/credentials on Linux or macOS, or at C:\Users\ USERNAME \. aws\credentials on Windows. This file can contain the credential details for the default profile and any named profiles.

How do I change the default profile 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. Copied!

How do I use AWS profiles with the AWS CLI?

Using profiles with the AWS CLI. To use a named profile, add the --profile profile-name option to your command. The following example lists all of your Amazon EC2 instances using the credentials and settings defined in the user1 profile from the previous example files. $ aws ec2 describe-instances --profile user1.

Why is the --profile parameter not working in AWS?

the value passed to the --profile parameter has been misspelled or the profile is not configured in the AWS credentials file the environment variable AWS_PROFILE has been set and points to a profile that is not present in the AWS credentials file When set, the AWS_PROFILE environment variable overrides the behavior of using the default AWS profile.

What does the AWS config profile could not be found error mean?

The "config profile could not be found" error occurs when we try to execute an AWS CLI command with a profile that's not configured in the AWS credentials file. The most common scenarios are: the value passed to the --profile parameter has been misspelled or the profile is not configured in the AWS credentials file

Why am I getting an AWS CLI installation error?

This error means that the operating system can't find the AWS CLI program. The installation might be incomplete. If you use pip to install the AWS Command Line Interface (AWS CLI), you might need to add the folder that contains the aws program to your operating system's PATH environment variable,...


2 Answers

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] 
like image 169
Mina Luke Avatar answered Oct 10 '22 15:10

Mina Luke


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.

like image 32
Garreth McDaid Avatar answered Oct 10 '22 15:10

Garreth McDaid