So my question is similar to this other one: V3 AWS S3 JavaScript SDK on deleteObjectCommand 204 response code
... I get the same answer:
{
'$metadata': {
httpStatusCode: 204,
requestId: 'WK2PAFG132EBSCB5',
extendedRequestId: 'tx6+bepnRyJxR3UfurfLAjRDtIiu17Q5UlerzkNFE54NpXXsdgkmFhLHSsN8tQlgTQZonQnSa5Y=',
cfId: undefined,
attempts: 1,
totalRetryDelay: 0
}
}
But when I go check in my bucket, the file is still there. If I run a ListObjectsV2Command, the file is listed, as if no delete command happened. Being patient doesn't seem to help, the file doesn't disappear.
Code is as simple as it gets:
const command = new s3client.DeleteObjectCommand({
Bucket: MY_S3BUCKET,
Key: path,
});
const response = await client.send(command)
console.log(response);
And my other operations, like getSignedUrl or ListObjectsV2Command are working fine. I thought about policy issues, but I did my best to give all powers to this user on this bucket. Also, I would expect a decent error message if policy were an issue, like 401 "not authorized".
Any idea what I'm doing wrong?
You'll get a 204 No Content response when deleting an S3 object if you have the necessary permission and the object was deleted. However, you'll also get the same response if you have the necessary permission and the object does not exist. So, in a sense, the DeleteObject API simply ensures that the object no longer exists.
Unrelated, it's quite common for S3 users to create S3 object keys from a corresponding Unix or MacOS OS file system path which looks like /folder1/folder2/file.pdf
and begins with a /
. S3 object keys, however, look like folder1/folder2/file.pdf
and do not begin with a /
.
So, I think you're attempting to delete the wrong key. Specifically the key you're deleting begins with an errant /
and that operation succeeds and returns 204, but doesn't actually delete anything.