Search code examples
ibm-cloudbotoobject-storageibm-cloud-storage

IBM COS - can't get or create bucket with boto


from boto.s3.connection import S3Connection 
conn = S3Connection('****', '****', host='s3.eu-geo.objectstorage.softlayer.net')
mybucket = conn.get_bucket('mybucket')

Returns

/anaconda3/lib/python3.6/site-packages/boto/s3/connection.py in head_bucket(self, bucket_name, headers)
    551             err.error_code = 'NoSuchBucket'
    552             err.error_message = 'The specified bucket does not exist'
--> 553             raise err
    554         else:
    555             raise self.provider.storage_response_error(

S3ResponseError: S3ResponseError: 404 Not Found

However, if I try to create the bucket:

conn.create_bucket('mybucket')

S3CreateError: S3CreateError: 409 Conflict
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Error><Code>BucketAlreadyExists</Code><Message>Container mybucket exists</Message><Resource>/mybucket/</Resource><RequestId>****</RequestId><httpStatusCode>409</httpStatusCode></Error>

Solution

  • Bucket names are universally unique in IBM Cloud object storage (or AWS S3). Deletion of a bucket is eventually consistent, and takes 10 mins to propagate, which means that a bucket name for a recently deleted bucket (by you or any other user) will take some time to be available again. The error you mentioned shows that the bucket 'mybucket' has been recently deleted, and is in a period where the name is not available. Generally it is suggested to use some specific prefix before bucket names, if it is something common (like mybucket). Check out this excerpt from the IBM COS API docs:

    A DELETE issued to an empty bucket deletes the bucket. After deleting a bucket the name will be held in reserve by the system for 10 minutes, after which it will be released for re-use. Only empty buckets can be deleted. This operation does not make use of operation specific headers, query parameters, or payload elements.