LoginSignup
0
0

More than 3 years have passed since last update.

[Cloudian #6] Python(boto3)で、バケットに格納されているオブジェクトを削除してみる

Last updated at Posted at 2020-12-18

はじめに

Cloudianは、AWSのS3完全互換のAPIを持ったオブジェクトストレージです。
前回は、Python(boto3)で、オブジェクトのリスト表示してみました。

今回は、Python(boto3)で、オブジェクトストレージのバケットに格納されているオブジェクトを削除してみようと思います。

バケットに格納されているオブジェクトの削除 / delete_object()

Cloudianにアップロードされたファイル(オブジェクト)を、delete_object()を使って削します。

以下の例では、バケット「pythonbucket1」に保存されているキー「10mb.dat」の、最新バージョンのオブジェクトを削除しています。

test.py
import boto3

client = boto3.client(
    's3',
    endpoint_url='https://xxx.yyy.com'
)


# バケット名:pythonbucket1 のオブジェクト:10mb.datファイル を削除
client.delete_object(Bucket='pythonbucket1', Key='10mb.dat')
{'ResponseMetadata': {'RequestId': '9dad3b68-0e30-1dbc-a754-06bdfcde1d5e',
  'HostId': '',
  'HTTPStatusCode': 204,
  'HTTPHeaders': {'date': 'Sun, 13 Dec 2020 22:27:45 GMT',
   'x-amz-request-id': '9dad3b68-0e30-1dbc-a754-06bdfcde1d5e',
   'server': 'CloudianS3'},
  'RetryAttempts': 0}}

まとめ

Python(boto3)で、オブジェクトを削除してみました。

次回も、Pythonでオブジェクトストレージ/Cloudianをいろいろ操作していきたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0