Pure.Krome
Pure.Krome

Reputation: 86967

How to confirm that Deleting an object from S3 Amazon actually worked / deleted?

I'm trying to check whether an object was deleted from Amazon S3. In my test scenario, i know the object doesn't exist because I'm trying to delete a file with a random Guid filename.

enter image description here

When I delete the file, I get back the a similar response as to when I delete a file from S3 which does exist.

here's a response when I delete an existing file:

enter image description here

here's a response when I attempt to delete a file that doesn't exist:

enter image description here

So i'm not too sure how to check this :(

Side note (or a potential clue?) - this bucket has VERSIONING turned on / active. I think this used to work on the bucket when versioning was off and the HttpStatusCode was something else when the file didn't exist when attempting a delete.

Also - before people suggest this - Yes, i know I can do this in TWO steps (delete, then check if exists) but this is now TWO round trips and I'm really hoping I don't need to do that as it feels like the 2nd call is a waste.

Upvotes: 1

Views: 3783

Answers (1)

Dennis Traub
Dennis Traub

Reputation: 51634

It’s important to understand that Amazon S3 provides eventual consistency for DELETES in all AWS Regions. Additionally, Amazon S3 replicates data across multiple servers in your chosen AWS Region. This means that when you delete an object, it can take some time for the deletion to replicate across all the servers. You might see that if you try to read an object immediately after deleting it, then Amazon S3 returns the object.

You can use one of the following ways to confirm that the object is in the process of deletion:

  • Enable the debug option on the AWS Command Line Interface (AWS CLI). Then, run the head-object command using the AWS CLI. If the response from a head-object command includes a DeleteMarker header, then this means that the object was deleted. If the response doesn't include a DeleteMarker header, then the object wasn't deleted.

  • Use an AWS SDK to send a HeadObject API call. If the x-amz-delete-marker field in the response is true, then the object was deleted. If x-amz-delete-marker is false, then the object wasn't deleted.

Source: https://aws.amazon.com/premiumsupport/knowledge-center/s3-listing-deleted-objects/

Upvotes: 1

Related Questions