Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 212
marco Avatar asked Feb 28 '20 21:02

marco


3 Answers

@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.

like image 162
marco Avatar answered Nov 20 '22 22:11

marco


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
like image 3
syumaK Avatar answered Nov 20 '22 22:11

syumaK


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.

like image 1
Irfan Avatar answered Nov 20 '22 21:11

Irfan