's3 pre-signed url for buckets in us-east-1, us-west-1, us-west-2 missing fields

I am trying to generate s3 pre-signed url so that I can PUT objects into my buckets from the client side. My regions of interest initially were:

  1. ap-northeast-2 (seoul)
  2. ap-south-1 (mumbai)
  3. us-east-1
  4. us-west-2

Below is the code I use to get the signed url:

const AWS = require("aws-sdk");
const { v4: uuidv4 } = require("uuid");

const region_name = "x-region";
const upload_bucket = "bucket-in-x-region";
AWS.config.update({ region: region_name });
const s3 = new AWS.S3();

async function getPresignedUrl() {
  const random_id = uuidv4();
  const obj_key = `${random_id}.png`;
  const s3Params = {
    Bucket: upload_bucket,
    Key: obj_key,
    Expires: 60,
    ContentType: "image/png",
    ACL: "public-read",
  };
  const presigned_url = await s3.getSignedUrlPromise("putObject", s3Params);
  return presigned_url;
}

getPresignedUrl().then((data) => {
  console.log(data);
});

Buckets in ap-northeast-2 and ap-south-1 returns a WORKING signed-url with the fields: Content-Type, X-Amz-Algorithm, X-Amz-Credential, X-Amz-Date, X-Amz-Expires, X-Amz-Security-Token, X-Amz-Signature, X-Amz-SignedHeaders, x-amz-acl

However the all buckets I tried based in regions: us-east-1, us-west-1 and us-west-2 returns a NON WORKING url with only the following fields: Content-Type, Expires, Signature, x-amz-acl

When I run this code in lambda, the invocation role has a policy with the following statement:

  {
            "Effect": "Allow",
            "Action": [
                "s3:PutObject",
                "s3:PutObjectAcl"
            ],
            "Resource": [
                "arn:aws:s3:::bucket-name-mumbai/*",
                "arn:aws:s3:::bucket-name-seoul/*",
                "arn:aws:s3:::bucket-name-useast/*",
                "arn:aws:s3:::bucket-name-uswest/*",
            ]
        }

Any ideas will be appreciated.



Solution 1:[1]

Add signatureVersion: 'v4' in AWS config and it should work:

AWS.config.update({ region: region_name, signatureVersion: 'v4' });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edward Ji