[Cloudian # 7] Try deleting the bucket in Python (boto3)

Introduction

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 bucket / delete_bucket ()

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

Summary

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

[Cloudian # 7] Try deleting the bucket in Python (boto3)
[Cloudian # 6] Try deleting the object stored in the bucket with Python (boto3)
[Cloudian # 2] Try to display the object storage bucket in Python (boto3)
[Cloudian # 8] Try setting the bucket versioning with Python (boto3)
[Cloudian # 5] Try to list the objects stored in the bucket with Python (boto3)
[Cloudian # 9] Try to display the metadata of the object in Python (boto3)
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try hitting the YouTube API in Python
[Cloudian # 3] Try to create a new object storage bucket with Python (boto3)
Try using the BitFlyer Ligntning API in Python
Try gRPC in Python
Try 9 slices in Python
Try implementing the Monte Carlo method in Python
Try using the DropBox Core API in Python
[Cloudian # 10] Try to generate a signed URL for object publishing in Python (boto3)
Download the file in Python
Find the difference in Python
Try LINE Notify in Python
Try implementing Yubaba in Python 3
Try scraping the data of COVID-19 in Tokyo with Python
Getting the arXiv API in Python
Save the binary file in Python
Hit the Sesami API in Python
Try the Python LINE Pay SDK
Get the desktop path in Python
Try implementing extension method in python
Try using LevelDB in Python (plyvel)
Get the script path in Python
Let's try Fizz Buzz in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Try to calculate Trace in Python
Try PLC register access in Python
Hit the web API in Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
Try using the Python Cmd module
Cython to try in the shortest
Get the host name in Python
Access the Twitter API in Python
Try using Leap Motion in Python
The first step in Python Matplotlib
I wrote the stack in Python
Master the weakref module in Python
To make sure that the specified key is in the specified bucket in Boto 3
Try transcribing the probability mass function of the binomial distribution in Python
Try running the basic information Python sample problem only in the browser
Try using FireBase Cloud Firestore in Python for the time being
Learn the design pattern "Builder" in Python
Load the remote Python SDK in IntelliJ
Try logging in to qiita with Python
Check the behavior of destructor in Python
Learn the design pattern "Flyweight" in Python
Learn the design pattern "Observer" in Python
Learn the design pattern "Memento" in Python
Try using the HL band in order
Learn the design pattern "Proxy" in Python
Write the test in a python docstring