boto3 format and location of credentials file

Viewed 1432

I'm just getting started with boto3 and tried the following code:

import boto3
boto3.session.Session(profile_name='Credentials')
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
    print(bucket.name)

If I name the section in ~/.aws/credentials [default], it works fine but if I name it something else, like [Credentials] and specify the profile_name as I did, it fails with

botocore.exceptions.NoCredentialsError: Unable to locate credentials

I want to be able to specify different profiles in the credentials file but I can't get past this error. Some people have answered this question saying that the section must be [default] but that cannot be right.

1 Answers
Related