0
votes

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.

  • I do not want to delete the delete marker.
  • Neither I want a single version of an object to be deleted.
  • Nor, I want to query all the versions of an object first and then send the DeleteObjectsAsync request.

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 ?

2
You have to create custom function where you iterate through the versions of the object and delete them.Rasik Jain
That's what I am trying to avoid.Code-47
You cannot avoid it.John Rotenstein

2 Answers

2
votes

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.

0
votes

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