Search code examples
amazon-web-servicesversioningbucket

Delete object in a bucket AWS


I come to you guys, because I would like to remove an object in a bucket aws. I activated the versioning on that bucket.

The object looks like that :

{
            "StorageClass": "STANDARD",
            "LastModified": "2020-06-12T00:49:29.700Z",
            "IsLatest": true,
            "Owner": {
                "DisplayName": "XXX",
                "ID": "XXXXXXXXXXXXX"
            },
            "Key": "my_file",
            "VersionId": "null",
            "Size": 165439242240,
            "ETag": "\"445fea819ed9cf0f127a39c64ec0da22-309\""
        }

I tried :

aws s3api delete-object --bucket my_bucket --key my_file --version-id version_id

That command creates a Delete Marker object , when I delete that Delete Marker , I get my starting my_file.

What I want to do is deleting definitely that file.


Solution

  • To permanently delete versioned objects, you must use DELETE Object versionId.

    aws s3api delete-object --bucket my_bucket --key my_file --version-id null
    

    More on delete object in AWS CLI Command Reference

    When you enable versioning on an existing bucket, objects that are already stored in the bucket are unchanged. The version IDs (null), contents, and permissions remain the same.

    To remove an object try this:

    aws s3 rm s3://mybucket/test.txt