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.
@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.
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"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With