I was thinking about deleting and then re-creating bucket (bad option which I realised later).
Then how can delete all objects from the bucket?
I tried this : http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Bucket.delete_objects
But it deletes multiple objects not all.
can you suggest what is the best way to empty bucket ?
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Bucket name list, select the option next to the name of the bucket that you want to empty, and then choose Empty.
Deleting S3 buckets, option 1: out-of-the-box tools According to AWS support, it can take up to several days for the bucket to be emptied!
Just use aws cli.
aws s3 rm s3://mybucket --recursive
Well, for longer answer if you insists to use boto3. This will send a delete marker to s3. No folder handling required. bucket.Object.all will create a iterator that not limit to 1K .
import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket('my-bucket') # suggested by Jordon Philips bucket.objects.all().delete()
If versioning is enabled, there's a similar call to the other answer to delete all object versions:
import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket('bucket-name') bucket.object_versions.delete()
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