Cloudian is fully compatible with S3, so it's convenient to use the AWS SDK! Last time tried to delete the object in Python (boto3).
This time, I will try to delete the object storage bucket with Python (boto3).
Delete the bucket created in Cloudian.
In the example below, the bucket "python bucket 1" is deleted.
test.py
import boto3
client = boto3.client(
's3',
endpoint_url='https://xxx.yyy.com'
)
#Bucket name:Remove pythonbucket1
client.delete_bucket(
Bucket='pythonbucket1'
)
{'ResponseMetadata': {'RequestId': '9dad3274-0e30-1dbc-a754-06bdfcde1d5e',
'HostId': '',
'HTTPStatusCode': 204,
'HTTPHeaders': {'date': 'Sun, 13 Dec 2020 20:12:33 GMT',
'x-amz-request-id': '9dad3274-0e30-1dbc-a754-06bdfcde1d5e',
'server': 'CloudianS3'},
'RetryAttempts': 0}}
- Caution To delete a bucket, there must be no objects in the bucket. If you execute delete_bucket () with an object in the bucket, you will get a BucketNotEmpty exception like the one below.
client.delete_bucket( Bucket='bucket1' )
ClientError Traceback (most recent call last) <ipython-input-3-0bb1849245e5> in <module> 1 client.delete_bucket( ----> 2 Bucket='bucket1' 3 ) ~/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/botocore/> client.py in _api_call(self, *args, **kwargs) 314 "%s() only accepts keyword arguments." % py_operation_name) 315 # The "self" in this scope is referring to the BaseClient. --> 316 return self._make_api_call(operation_name, kwargs) 317 318 _api_call.__name__ = str(py_operation_name) ~/.pyenv/versions/anaconda3-2019.03/lib/python3.7/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params) 624 error_code = parsed_response.get("Error", {}).get("Code") 625 error_class = self.exceptions.from_code(error_code)
--> 626 raise error_class(parsed_response, operation_name)
627 else: 628 return parsed_response
ClientError: An error occurred (BucketNotEmpty) when calling the DeleteBucket operation: The bucket you tried to delete is not empty
I tried deleting the bucket in Python (boto3).
Next time, I would like to operate object storage/Cloudian in various ways with Python.
Recommended Posts