Code-47
Code-47

Reputation: 423

AWS S3: Delete all versions of an object from versioned bucket in single call

I have searched this topic on aws docs/several websites/stackoverflow and was not able to find any answer.

I want to delete all the versions of an object in versioned s3 bucket in a single call.

Is there any way to delete all the versions of an object, whether it has delete marker or not, in a single call to AWS using S3's .net SDK ?

Upvotes: 4

Views: 8366

Answers (2)

Dikshit Kathuria
Dikshit Kathuria

Reputation: 1312

I did the same for one of my clients. We were using S3 to store many versions of a single file. After surfing the web pretty much, I was not able to find any method. The best approach is to just loop over the S3 file versions. Helpful steps:

  1. Get all versions of the object that you wish to delete.
  2. Loop onto these versions and delete one by one.

Note: I observed a weird behavior of S3 where after deleting all the versions of an object, I sometimes found a Delete Marker being created. Well of course if you delete the file from S3 console, you get a delete marker. But in my case, doing it though NodeJs, I found that only some times. So you need to handle that as well in your code. This is how I did it in NodeJS

        if (data.Deleted.DeleteMarker) {
          console.log('Found delete marker', data.Deleted.DeleteMarker);
          //Handle here to delete the deleteMarker
          }

Thanks, Upvote if it helped.

Upvotes: 4

Anton
Anton

Reputation: 4062

There is no single call for this. Even AWS gives you the "iterate trough all the versions" example as a solution: https://docs.aws.amazon.com/AmazonS3/latest/dev/delete-or-empty-bucket.html#delete-bucket-sdk-java

Upvotes: 0

Related Questions