The documentation on boto3 claims that delete_object will return:
{
'DeleteMarker': True|False,
'VersionId': 'string',
'RequestCharged': 'requester'
}
I planned to use the DeleteMarker as a verification that the delete was executed.
Currently it returns:
{'ResponseMetadata': {'HTTPHeaders': {'date': 'Tue, 09 Aug 2016 17:18:09 GMT',
'server': 'AmazonS3',
'x-amz-id-2': '*_/__',
'x-amz-request-id': '__'},
'HTTPStatusCode': 204,
'HostId': '__/_*_',
'RequestId': '_**'}}
This is after doing a successful delete on s3.
Based on the documentation, the delete marker is only used if your bucket is versioned.
In general, if you do not get an error propagated from the client call, then the request was successful; there is no need to check the response for delete_object to see if it was successful.
Let us know if you have any more questions.
It seems that the response is always the same, whenever the object exists or not in the S3 bucket.
Is there any way to really differentiate a successful and unsuccessful delete request?
Hey, I realize this is a very old and very dead ticket, but I'd like to raise this one again. I'm trying to delete objects and confirm deletion via the boto response, but the response does _not_ line up with the documentation at all.
What I expected:
{
'DeleteMarker': True|False,
'VersionId': 'string',
'RequestCharged': 'requester'
}
What I got:
{'ResponseMetadata': {'RetryAttempts': 0, 'HTTPHeaders': {'date': 'Fri, 10 Mar 2017 20:28:16 GMT', 'x-amz-id-2': '***,
'server': 'AmazonS3',
'x-amz-request-id': '***'},
'HTTPStatusCode': 204,
'HostId': '***',
'RequestId': '***'}
}
+1 in the same situation. always get a 204 with same data
Not sure if this has been resolved, but just under a year on and I still only get 204s which contradicts the docs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Object.delete
And whilst I understand that this may only refer to versioned files, it would be really useful to know if the file was in fact removed, or not (and why).
Thanks,
A potential workaround is to first check if the object exists. If the object does not exist, this first call can return 404. If the object exists, then you could assume the 204 from a subsequent delete_object call has done what it claims to do :)
# https://stackoverflow.com/a/33843019/3594865
import boto3
import botocore
s3 = boto3.resource('s3')
try:
s3.Object('my-bucket', 'dootdoot.jpg').load()
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
# The object does not exist.
...
else:
# Something else has gone wrong.
raise
else:
# The object does exist.
...
I see that the ticket was closed but it still behaves the same..
NOTE: After downloading the file and making sure it exist, I manage to delete it without issues but the documentation and Status code are quite confusing..
Still behaves the same. Doesn't make much sense to me to receive the same response either on success or failed request, but ok.
Hello, Indeed same response makes no sense for both success or failed operation, but I think the issue has to do with the delete_object() operation initiating a request to delete the object across all s3 storage. s3 will replicate objects multiple times, so its actually better to check if the object has been delete by initiating a trigger when the removed object event happens in S3.
https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#notification-how-to-event-types-and-destinations
Most helpful comment
+1 in the same situation. always get a 204 with same data