Question

DigitalOcean Spaces Call list_buckets returns nothing

I’ve seen a lot of people have problems with this online and now I’ve run into the issue myself. I’m trying to use boto3 to list_buckets in a DigitalOcean Spaces. It returns a 200 status code, however there are no buckets listed inside. Strangely enough, I can create a bucket through code, but I can’t list it.

People have reported having success when they use different endpoint URLs. I’ve used the following:

https://<space_name>.nyc3.digitaloceanspaces.com
https://nyc3.digitaloceanspaces.com

No luck with either of them.

import boto3
s3 = boto3.client('s3', region_name=region, endpoint_url=endpoint, aws_access_key_id=access_id, aws_secret_access_key=secret_key)
s3.list_buckets()

list_buckets returns the following response.

{'ResponseMetadata': {'RequestId': 'tx00000000000010c9ce0be-0061b571d4-1800930a-nyc3c', 'HostId': '', 'HTTPStatusCode': 200, 'HTTPHeaders': {'transfer-encoding': 'chunked', 'x-amz-request-id': 'tx00000000000010c9ce0be-0061b571d4-1800930a-nyc3c', 'content-type': 'application/xml', 'date': 'Sun, 12 Dec 2021 03:51:48 GMT', 'strict-transport-security': 'max-age=15552000; includeSubDomains; preload'}, 'RetryAttempts': 0}}

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello, @jaskiemr

I’ve not used boto3’s python library but it seems that the response should be different according to Boto 3 Docs:

Response syntax should be:

{
    'Buckets': [
        {
            'Name': 'string',
            'CreationDate': datetime(2015, 1, 1)
        },
    ],
    'Owner': {
        'DisplayName': 'string',
        'ID': 'string'
    }
}

Usually, for an upload, you will use the short name - nyc3.digitaloceanspaces.com:

import boto3

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='ACCESS_KEY',
                        aws_secret_access_key='SECRET_KEY')

client.upload_file('/path/to/file.ext',  # Path to local file
                   'my-space',  # Name of Space
                   'file.ext')  # Name for remote file

So I’ll recommend sticking to that format. Something like:

import boto3

session = boto3.session.Session()
client = session.client('s3',
                        region_name='nyc3',
                        endpoint_url='https://nyc3.digitaloceanspaces.com',
                        aws_access_key_id='ACCESS_KEY',
                        aws_secret_access_key='SECRET_KEY')

list_buckets = client.list_buckets()
 
for bucket in list_buckets['Buckets']:
    print(bucket['Name'])

Hope that this helps! Regards, Alex