boto – Boto3 Error: botocore.exceptions.NoCredentialsError: Unable to locate credentials
boto – Boto3 Error: botocore.exceptions.NoCredentialsError: Unable to locate credentials
try specifying keys manually
s3 = boto3.resource(s3,
aws_access_key_id=ACCESS_ID,
aws_secret_access_key= ACCESS_KEY)
Make sure you dont include your ACCESS_ID
and ACCESS_KEY
in the code directly for security concerns.
Consider using environment configs and injecting them in the code as suggested by @Tiger_Mike.
For Prod environments consider using rotating access keys:
https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_RotateAccessKey
I had the same issue and found out that the format of my ~/.aws/credentials
file was wrong.
It worked with a file containing:
[default]
aws_access_key_id=XXXXXXXXXXXXXX
aws_secret_access_key=YYYYYYYYYYYYYYYYYYYYYYYYYYY
Note that there must be a profile name [default]
. Some official documentation make reference to a profile named [credentials]
, which did not work for me.
boto – Boto3 Error: botocore.exceptions.NoCredentialsError: Unable to locate credentials
If you are looking for an alternative way, try adding your credentials using
AmazonCLI
from the terminal type:-
aws configure
then fill in your keys and region.