1

I'm using

>>> s3 = session.client(service_name='s3',
... aws_access_key_id='access_key_id_goes_here',
... aws_secret_access_key='secret_key_goes_here',
... endpoint_url='endpoint_url_goes_here')
>>> s3.list_buckets() 

to list out my existing buckets, but got the error botocore.exceptions.ClientError: An error occurred () when calling the ListBuckets operation: Not sure how to proceed from that

1 Answer 1

2

Are you using boto3?

Here is some sample code. There are two ways to use boto:

  • The 'client' method that maps to AWS API calls, or
  • The 'resource' method that is more Pythonic

boto3 will automatically retrieve your user credentials from a configuration file, so there is no need to put credentials in the code. You can create the configuration file with the AWS CLI aws configure command.

import boto3

# Using the 'client' method
s3_client = boto3.client('s3')

response = s3_client.list_buckets()

for bucket in response['Buckets']:
    print(bucket['Name'])

# Or, using the 'resource' method
s3_resource = boto3.resource('s3')

for bucket in s3_resource.buckets.all():
    print(bucket.name)

If you are using an S3-compatible service, you can add a endpoint_url parameter to the client() and resource() calls.

1
  • Yes I'm using boto3 and an S3-compatible service (OpenStack swift), however, when I followed your code I still got the same error. Maybe it's because of my swift configuration
    – Jack Yu
    Commented Jul 5, 2021 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.