I’m trying to create an S3 bucket using Boto3 in Python, but I keep running into this error:
botocore.exceptions.NoCredentialsError: Unable to locate credentials
Here’s a simplified version of my code:
import boto3
import uuid
s3 = boto3.resource('s3')
bucket_name = "python-sdk-sample-%s" % uuid.uuid4()
print("Creating new bucket with name:", bucket_name)
s3.create_bucket(Bucket=bucket_name)
I’ve already saved my credentials in:
C:\Users\myname\.aws\credentials
and I expected Boto3 to read them automatically. I also enabled debug logging:
boto3.set_stream_logger('botocore', level='DEBUG')
The log shows that Boto3 is checking all usual credential sources (environment variables, shared credentials file, config file, IAM roles, etc.) but still cannot find my credentials.
I’m looking for guidance on why botocore.exceptions.nocredentialserror: unable to locate credentials occurs in this situation and what the proper way is to make Boto3 recognize my credentials on Windows.
Any step-by-step advice or common pitfalls would be really helpful.