S3 gives SignatureDoesNotMatch error for PutObject command pre-signed url using aws-sdk v3

Viewed 2379

My Amazon S3 buckets were working fine until I decided to update my aws sdk from version v2 to the modular v3.

I am able to programatically upload the file using the sdk but I am not able to upload files using the pre-signed url it generates.

      const { getSignedUrl } = require('@aws-sdk/s3-request-presigner');
      const { S3Client, , PutObjectCommand } = require('@aws-sdk/client-s3');
      const s3Client = S3Client({ region: 'us-east-2'});
      const params = {
        Bucket: '<bucket>',
        Key: '1234567890.jpg',
        ACL: 'private',
        ContentType: 'image/jpg',
        // Body: '<base64 encoded image content>'
      };
      const command = new PutObjectCommand(params);
      // await s3Client.send(command); // works fine
      const signedUrl = await getSignedUrl(s3Client, command); // generated signed url fails to upload image

When I try to make a PUT request using the presigned url generated I get a 403 HTTP error code and a message SignatureDoesNotMatch. Please guide me on what I might be missing because I've been working on this for two days now.

1 Answers

Have you tried this;
https://www.digitalocean.com/community/questions/signature-does-not-match-when-putting-to-presigned-spaces-upload-url
Here is a link for more details;
https://www.msp360.com/resources/blog/s3-pre-signed-url-guide/
Related