marco
marco

Reputation: 385

Boto3 Session "The config profile () could not be found"

Now, this a a weird one. I have created a config in ~/.aws/config

[profile dev_config]
output = json
region = us-east-1

I also have credentials in my ~/.aws/credentials file. FYI, info is blank on purpose.

[dev_config]
aws_access_key_id = ...
aws_secret_access_key = ...
aws_session_token = ...

When I run my python script, I execute

session = boto3.Session(profile_name="dev_config")
s3client = session.client('s3')

For some reason, I get the error

'The config profile (dev_config) could not be found'

I am absolutely stumped on this one because everything seems correct with my config and credentials file. All of the forums suggest that my config or credentials file is set up wrong but I have everything in place. It's like boto3 cannot file my files for some reason. I am running this through pycharm in centos7 btw. If anyone has anything else I should check for, please help.

Also, I know this is a similar question as to other posts, but none of those are helpful to me right now. They all point to a bad config like I said.

Upvotes: 11

Views: 28258

Answers (4)

Chapi Menge
Chapi Menge

Reputation: 136

After i did what the accepted answer did. the below happens.

AWS_CONFIG_FILE=/home/..../.aws/config/
AWS_SHARED_CREDENTIALS_FILE/home/..../credentials

In my case it was my .env file also raising an issue. so in my .env file i did something like below

AWS_PROFILE='AWSPROFILE-dev'

which the quote was raising the issue when comparing the profile. See the below images to see how I track down the issue. enter image description here

enter image description here

enter image description here

As you see the error was due to the string quote. it is gone after I removed the quote from the .env file like below.

AWS_PROFILE=AWSPROFILE-dev

idk why it acts like this but maybe I am using Makefile or something else. Hopefully it is helpful.

Upvotes: 0

Irfan
Irfan

Reputation: 576

I faced a similar issue and as others said Boto3's default location for config file is ~/.aws/config. Since I was using Git bash on Windows, this path was pointing to C:\Windows\System32\config\systemprofile\.aws\config for me, but It already had the AWS config profile Boto3 was complaining about.

It turned out it was the 64-bit version of this path C:\Windows\SysWOW64\config\systemprofile\.aws\config where Boto3 was expecting the config file which wasn't there. As soon as I copied the config and credentials files into this folder Boto3 stopped complaining.

Upvotes: 2

marco
marco

Reputation: 385

@Syumak, thanks for the response. The solution in my case turned out to not be obvious, but hopefully this will help someone else that may come across the same issue.

The problem is that boto3 has the default location for the config file as

AWS_CONFIG_FILE = ~/.aws/config

In either your .env file for your project or in your global env file on your system, you need to set the AWS_CONFIG_FILE location to the actual path rather than the one above. So in my case, I did the following in my .env file.

AWS_CONFIG_FILE = /home/<user>/.aws/config
AWS_SHARED_CREDENTIALS_FILE = /home/<user>/.aws/credentials

My program was able to locate the config file after that.

Upvotes: 13

aksyuma
aksyuma

Reputation: 3180

Can you try the following suggestions and check if your setup works :

Option One:

Edit ~/.aws/config file as shown below :

[profile dev_config]
output = json

Edit ~/.aws/credentials file as shown below :

[dev_config]
aws_access_key_id = ...
aws_secret_access_key = ...
region = us-east-1

If the above suggestion doesn't work, proceed to suggestion two below.

Option Two:

aws configure --profile "dev_config"
  • Run the above command and paste your access key & secret key again. This command will update your credentials profile which is an easier way to get this setup working

Upvotes: 3

Related Questions