Whats the best way to delete many cloudstorage objects? I have a bucket that contains ~500K objects and I'd like to delete them all.
Do you I have to make 1 api request for each object I want to delete or is there some sort of batch method? I'm currently using gsutil to delete one at a time.
You need to make 1 api request for each object. The simplest way to accomplish this would be with gsutil:
$ gsutil -m rm gs://bucket_with_many_objects/**
The -m option enables multithreading, which will delete many objects in parallel.
Note that with gsutil the "*" wildcard will only match the top-level objects (up to the next "/" in the path name). If you want to delete all the objects you can either use:
$ gsutil -m rm -R gs://bucket_with_many_objects
or
$ gsutil -m rm gs://bucket_with_many_objects/**
Mike Schwartz, Google Cloud Storage Team
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With