Reputation: 21
I want to delete multiple GCS keys wih Boto. In it's documentation it suggests that there's a multi-object delete method (delete_keys), however I cannot get it to work.
According to this article it is possible for Amazon S3:
s3 = boto.connect_s3()
bucket = s3.get_bucket("basementcoders.logging")
result = bucket.delete_keys([key.name for key in bucket if key.name[-1] == '6'])
result.deleted
However when i try the same thing for Google Storage it doesn't work:
bucket = BotoConnection().get_bucket(bucketName)
keys = [key for key in bucket]
print len(keys)
result = bucket.delete_keys(keys)
print result.deleted
print result.errors
Traceback (most recent call last):
File "gcsClient.py", line 166, in <module>
GcsClient.deleteMultipleObjects('debug_bucket')
File "gcsClient.py", line 155, in deleteMultipleObjects
result = bucket.delete_keys(keys)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 583, in delete_keys
while delete_keys2(headers):
File "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 582, in delete_keys2
body)
boto.exception.GSResponseError: GSResponseError: 400 Bad Request
Upvotes: 2
Views: 602
Reputation: 5511
This uses S3's multi-object delete API, which Google Cloud Storage does not support. Thus, it is not possible to do it this way for Google Cloud Storage - you will need to call delete_key () once per key.
Upvotes: 1