S3 DeleteObject - DeleteMarker always returns empty

I am using the AWS SDK for PHP, version 2.4.7 installed through the composer. After deleting a file from the S3 bucket, the DeleteMarker key in the response object is always empty, even if the file is actually deleted from S3. The documentation states that DeleteMarker must be true if the operation was successful, otherwise it will be false.

My call to delete:

// delete S3 object $result = $s3->deleteObject(array( 'Bucket' => $this->_bucket, 'Key' => $object_key, )); 

and the answer is:

 Guzzle\Service\Resource\Model Object ( [structure:protected] => [data:protected] => Array ( [DeleteMarker] => [VersionId] => [RequestId] => 2CC3EC60C4294CB5 ) ) 

If I then do:

  // check if was deleted $is_deleted = (bool) $result->get('DeleteMarker'); 

$ is_deleted is always false. How can it be that there is no value returned against the DeleteMarker key, even if the delete operation was actually successful and the file was deleted from S3?

UPDATE:

If I add a slash to the beginning of my key, I get a false response back, even if the file is still deleted from S3.

The key "path / to / my / image.jpg" leads to the fact that DeleteMarker has an empty value The key "/path/to/my/image.jpg" leads to the fact that DeleteMarker has an empty false

But in both cases, the images are deleted from the S3 bucket.

+6
source share
2 answers

When converting from SDK v. 1? to 2.?, I also ran into the problem of not knowing if the file was deleted (I used the ->isOK() method in almost everything that would tell me if the file was deleted or not).

I finally stumbled across this answer from the creator of Guzzle: https://forums.aws.amazon.com/thread.jspa?messageID=455154

Basically, there is no longer any type of flag. What Michael suggests (Guzzle): if you want to find out if the file has been deleted, use ->deleteObject() and then run ->doesObjectExist() to verify that the deletion was successful.

The rationale for the changes is this: the new approach allows you to dump tons of delete requests without having to wait for answers, etc.

What is it worth? David

+7
source

I have the same issue with the Javascript SDK. Calling deleteObject returns a penalty (HTTP 204) whether the file exists or not! This makes it impossible to determine if the file was deleted from the response code. In addition, it seems that the answer only includes DeleteMarker if the bucket has version control (see also this thread on DeleteMarker ).

I see two possibilities to solve this problem.

As a first option, you can enable version control and use the DELETE Object versionID to permanently delete your objects ( see AWS documentation ). This will require you to either save the versionID in your database, or request it before deletion using listObjectVersions

As a second option, you can use listObjects to check if the file exists, delete the file with deleteObject and check listObjects again to make sure the file has been deleted exactly.

I am not happy with any of the solutions, but they are doing this job now

+2
source

Source: https://habr.com/ru/post/956538/