aws-sdk-js
aws-sdk-js copied to clipboard
403 forbidden returned when calling deleteObject() (s3)
Describe the bug
Status code 204 and 403 are returned when trying to delete object from S3 bucket; object is still deleted.
Expected Behavior
Get only 204 response and have the object deleted from bucket
Current Behavior
I get both a 204 and 403 forbidden when trying to delete an object from my bucket with an error that says:
"SignatureDoesNotMatch: The request signature we calculated does not match the signature you provided. Check your key and signing method."
The object is still removed from the bucket.

Reproduction Steps
import AWS from 'aws-sdk';
const s3 = new AWS.S3({
accessKeyId: AWS_S3_ACCESS_KEY_ID,
secretAccessKey: AWS_S3_SECRET_ACCESS_KEY,
region: AWS_S3_BUCKET_REGION,
});
//calling this method:
async deleteImageFromBucket(key: string): Promise<any> {
try {
const response = await s3
.deleteObject(
{
Bucket: AWS_S3_REKOGNITION_BUCKET,
Key: key,
},
(err, data) => {
console.log('err: ', err);
console.log('data: ', data);
}
)
.promise();
return response;
} catch (error) {
return error;
}
}
Possible Solution
No response
Additional Information/Context
No response
SDK version used
"aws-sdk": "^2.1057.0"
Environment details (OS name and version, etc.)
ubuntu 22.04
Hey @ekrausso thanks for opening this issue, can you share more information on you use case. Do you see the error everytime you execute the API? Trying to find what causes this error to occur to try and reproduce it.
Using just code below doesnt error out for me:
var params = {
Bucket: "examplebucket",
Key: "objectkey.jpg"
};
s3.deleteObject(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
/*
data = {
}
*/
});
Hi @ajredniwja .. Im uploading an image to a bucket to run some rekognition methods on and deleting the object after its done. It just returns both 204 and 403 everytime with this 'SignatureDoesNotMatch' error.
This is literally all the code Im using:
public async deleteImageFromBucket(key: string): Promise<any> {
return await s3
.deleteObject(
{
Bucket: AWS_S3_REKOGNITION_BUCKET,
Key: `referenceImages/${key}`,
},
(err, data) => {
console.log(`err: ${err}\ndata: ${data}`);
}
)
.promise();
}
Hi @ekrausso, what I could see is that two requests are being performed against the service, and based on your code you do just one call. In my case I am getting the correct response so that I recommend you to either try with the latest version of the SDK, or check what could be doing causing this in your network, maybe a proxy, etc. You could also try to do a quick test with nodejs, instead from the browser, and see if you see the same behavior.
Here is the code I used:
import AWS from "aws-sdk";
const client = new AWS.S3({
region: 'us-east-2'
});
const response = await client.deleteObject({
Bucket: process.env.TEST_BUCKET,
Key: process.env.TEST_KEY
}).promise();
console.log(response)
Thanks!
This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.