141

Every time I want to config something with AWS I get the following error :

"The config profile (myname) could not be found"

like : aws configure

I'm using Python 3.4 and I want to use AWS CLI Keyring to encrypt my credentials..

Steve Ritz
  • 2,017
  • 4
  • 12
  • 12
  • See also: http://serverfault.com/questions/491124/aws-cli-cant-find-my-config-even-through-it-exists – Jason Mar 19 '16 at 01:03
  • This happened to me when AWS config file was not found since the user starting the service was a root user, when i started the service with ubuntu user it found the config, problem solved! – Alok Kumar Singh Nov 19 '21 at 08:16

15 Answers15

164

I think there is something missing from the AWS documentation in http://docs.aws.amazon.com/lambda/latest/dg/setup-awscli.html, it did not mention that you should edit the file ~/.aws/config to add your username profile. There are two ways to do this:

  1. edit ~/.aws/config or

  2. aws configure --profile "your username"

ronald8192
  • 5,003
  • 2
  • 14
  • 23
Stanley Yong
  • 1,844
  • 1
  • 12
  • 7
  • The above other answers are useful but I think you're highlighting something important: if you go through the aws configure --profile protocols in the aws configure command line utility it will automatically update the .aws/configure file, which is easier. At first I tried to edit it in VIM and couldn't get it right. – ouonomos Oct 30 '16 at 17:21
  • Also: I think you have to get the lambda and IAM default region to be the same to get that to work. The region names in the pull-down are obscure, but the mapping of region name to region is here: http://docs.aws.amazon.com/general/latest/gr/rande.html – ouonomos Oct 30 '16 at 17:22
  • 1
    My build also failed without the output=json or text specified. – brianfit May 30 '17 at 19:22
  • 6
    Can you explain how to **create** a new profile with `aws configure` ? It seems that you need to bootstrap profile manually. Thanks. – Étienne Bersac Apr 26 '19 at 14:19
  • I have solved my problem by editing both ~/.aws/config and ~/.aws/credentials – Berk May 05 '20 at 12:23
  • Note that, in the above, AWS considers home "~" to be %USERPROFILE% ; not %HOME%, which might be somewhere else altogether. This was extra confusing to me because, another tool (gimme-aws-creds) was putting AWS configuration files in %HOME%, which, of course, AWS could not find, giving the error message from the OP. Basically... if you get this message, maybe check you put your config in the right home. – William Ellis Oct 07 '21 at 13:48
  • Fixed by adding links in `/root/.aws/` to point to /home/ubuntu/.aws. If you process run as root you might also face this. – Alok Kumar Singh Dec 24 '21 at 06:13
51

I ran into this problem when I moved to a new machine, carrying with me my AWS_DEFAULT_PROFILE environment variable, but not my ~/.aws directory. I couldn't get any awscli commands to work until I unset that variable or properly configured the named profile. But even the aws configure command was broken, making things a bit tricky. Assuming you have a Unix-like shell handy:

  1. To determine what AWS-specific variables you might have in your session: env | grep AWS_
    • if you don't see AWS_DEFAULT_PROFILE or AWS_PROFILE listed here, this answer is not applicable to you.
  2. To temporarily remove the default profile: unset AWS_DEFAULT_PROFILE and/or unset AWS_PROFILE
  3. To configure the profile in question: aws --profile foo configure
  4. To reset the default profile variable: exec $SHELL
  5. To test your new setup: aws iam get-user
billkw
  • 3,350
  • 3
  • 28
  • 32
10

can you check your config file under ~/.aws/config- you might have an invalid section called [myname], something like this (this is an example)

[default]
region=us-west-2
output=json

[myname]
region=us-east-1
output=text

Just remove the [myname] section (including all content for this profile) and you will be fine to run aws cli again

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
10

Working with profiles is little tricky. Documentation can be found at: https://docs.aws.amazon.com/cli/latest/topic/config-vars.html (But you need to pay attention on env variables like AWS_PROFILE)

Using profile with aws cli requires a config file (default at ~/.aws/config or set using AWS_CONFIG_FILE). A sample config file for reference: `

[profile PROFILE_NAME]
 output=json
 region=us-west-1
 aws_access_key_id=foo
 aws_secret_access_key=bar

`

Env variable AWS_PROFILE informs AWS cli about the profile to use from AWS config. It is not an alternate of config file like AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY are for ~/.aws/credentials.

Another interesting fact is if AWS_PROFILE 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.

user6058180
  • 101
  • 1
  • 4
5

In my case, I had the variable named "AWS_PROFILE" on Environment variables with an old value.

enter image description here

Jorge Freitas
  • 790
  • 10
  • 18
4

Use as follows

[profilename]
region=us-east-1
output=text

Example cmd

aws --profile myname CMD opts
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
  • 2
    i think this should be without "profile" in the square brackets? – Markus Köhler Aug 18 '16 at 13:13
  • 1
    @MarkusKöhler: Correct, had the same issue. Their docs on some places say otherwise: http://docs.aws.amazon.com/lambda/latest/dg/setup-awscli.html (probably outdated) – ddario Sep 08 '16 at 13:35
0

Did you actually set up your specific user? The walkthrough setup guide in AWS explains how to set a default user, and then how to set up additional users. If you didn't complete the full setup, you'll just have a default block and your myName won't have been created..

Mike Pinnell
  • 71
  • 1
  • 5
0

Was facing similar issue and found below link more helpful then the answers provided here. I guess this is due to the updates to AWS CLI since the answers are provided.

https://serverfault.com/questions/792937/the-config-profile-adminuser-could-not-be-found

Essentially it helps to create two different files (i.e. one for the general config related information and the second for the credentials related information).

shekharlondhe
  • 79
  • 1
  • 8
0

Make sure you are in the correct VirtualEnvironment. I updated PyCharm and for some reason had to point my project at my VE again. Opening the terminal, I was not in my VE when attempting zappa update (and got this error). Restarting PyCharm, all back to normal.

andyw
  • 3,505
  • 2
  • 30
  • 44
0

In my case, I was using the Docker method for the AWS CLI tool, and I hadn't read the instructions far enough to realize that I had to make my credentials directory visible to the docker container. https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-docker.html

Instead of

docker run --rm -it amazon/aws-cli:latest command args...

I needed to do:

docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli:latest command args...

BareMetalCoder
  • 569
  • 5
  • 17
0

Just in case anyone is trying to do this on a headless server (CI runner in my case, adding an EKS cluster config to kubeconfig).

The reason I have to do this is because the runner is in a different AWS account to the EKS cluster in question (and the aws eks command looks in same account).

I do have a way of authenticating to the correct AWS account which populates ~/.aws/credentials with valid creds.

First I authenticate to populate ~/.aws/credentials Then

cp ~/.aws/credentials ~/.aws/config
sed -i 's/profilename/profile profilename/g' ~/.aws/config

and then when I run following it works

aws eks update-kubeconfig --name cluster-name --profile profilename --region us-east-1
kafka
  • 553
  • 6
  • 19
0

I have faced the same issue while deploying the Flask application in Nginx and Gunicorn.

It may helpful for someone who faces the same issue as I was

My Case: generating rds AUTH Token using AWS credentials

In development mode it is working fine and able to fetch the AWS Config from the .aws folder

when I try to run it via Nginx-Gunicorn Its gets failed, Even though I gave all root permission to respective folders and services.

I have stored AccessKey and SecretKey in environment variables and creating auth token by using those credentials

import boto3,os
S3_KEY=os.environ['aws_access_key']
S3_SECRET=os.environ['aws_secret_access_key']
def generate_iam_rds_token(server,region,port,user,S3_KEY,S3_SECRET):
   s3_conn = boto3.client('rds', region_name=region,
                       aws_access_key_id=S3_KEY,
                       aws_secret_access_key=S3_SECRET)
   pwd = s3_conn.generate_db_auth_token(server, port, user, Region=region)
   return pwd
#call the method to get a token
server='https://example.com'
region='ap-west-3'
port='port_number'
user='db_user_name'
pwd_token=generate_iam_rds_token(server,region,port,user,S3_KEY,S3_SECRET)

SQLALCHEMY_DATABASE_URI = 'postgresql+psycopg2://{user}:{pwd}@{host}:{port}/{db}'.format(user=user,host=host,port=port,db=db,pwd=pwd)

Note: In Ubuntu Os, Login as root user by using sudo -s or respective user that you have configured in gunicorn and Do aws configure

Ramesh Ponnusamy
  • 1,553
  • 11
  • 22
0

Please note the issue can happen if the aws config file is not found for the user which is starting the service.

For me the issue was the service was starting the root user so it was not able to find the AWS config file. I fixed it by making the service start from non root user sot hat AWS config could be found.

Alok Kumar Singh
  • 2,331
  • 3
  • 18
  • 37
0

If you use windows and write a config/credentials by Windows Note app, the app make a file with ".txt" extension. So, you could remove file extension. In my case, it worked.

Jack
  • 125
  • 1
  • 1
  • 10
-2

For me it was because I had my .aws/config file looking like this:

[profile myname]
aws_access_key_id = ....
aws_secret_access_key = ....
region=us-west-1

I think the reason is I based it off my .aws/credentials file, which requires having [profile myname] for Zappa and maybe some other aws/elastic beanstalk tools.

When I changed config to this it worked great:

[myname]
aws_access_key_id = ....
aws_secret_access_key = ....
region=us-west-1
owenfi
  • 2,471
  • 1
  • 24
  • 37
  • 2
    The config files requires [profile XXX ] but the credentials file does not require the profile prefix. – cgseller Sep 18 '18 at 18:34