How do you completely delete an object via the S3 Console? "Completely delete" meaning the object is entirely gone and isn't visible when enabling "Show versions." I cannot delete the "Show versions" objects themselves as the button is greyed out when they're selected. I've also tried deleting them via CLI but have had no luck.
CodePudding user response:
Looks like your IAM User accessing the bucket does not have s3:DeleteObjectVersion permission. Once you add this permission to your policy, you should be able to delete the versions as well.
CodePudding user response:
If you have versioning enabled, deleting an object just adds another version of the object, the so called "delete marker". If you want to remove all versions, including the delete marker, you'll need to enumerate and delete all versions of the object. For instance, with the Python SDK, you can enumerate and delete them with one line after some setup:
import boto3
s3 = boto3.resource("s3")
bucket = s3.Bucket("-example-bucket-")
key = "example_object.txt"
object = bucket.object_versions.filter(Prefix=key)
versions = len(list(object.all()))
object.delete()
print(f"Delted {versions} versions for '{key}'")