1
votes

I want to get a pre-signed URL for my S3 bucket for a PUT request like this (in node.js)

   AWS.config.update({
      accessKeyId: s3Config.accessKeyId,
      secretAccessKey: s3Config.secretAccessKey,
      region: s3Config.region,
      signatureVersion: 'v4'
   });
   var s3bucket = new AWS.S3({params: {Bucket: s3Config.bucket,Key:'/content'}});
   s3Config.preSignedURL = s3bucket.getSignedUrl('putObject',{ACL:s3Config.acl})

as a result i get

https://[BUCKET].s3.[REGION].amazonaws.com/[KEY]?[presignedURLStuff]

This URL is according to Amazon wrong. The URL has to be in the format http://*.s3.amazonaws.com/*. I also get the Error net::ERR_INSECURE_RESPONSE from the pre-flight. What do I have to do that the function constructs the right URL. Removing the region from the URL leads to 400 Bad Request. Pre-flight OPTIONS works then.

1
In what region is the bucket located, and what is your perception of what the correct URL should be? For some regions, the format you seem to be showing is a valid alternative.Michael - sqlbot
Does the returned URL work?John Rotenstein
s3-eu-west-1 is my region. According to Amazon only URL in the format http://*.s3.amazonaws.com/* are valid and the returned URL gives me an Error, not even the pre-flight will come backMaurus WTFSt0n3d Dhler

1 Answers

0
votes

I believe a PUT request needs to go to a specific bucket region.

If for some reason the URL that you get back has the wrong region for your bucket (say your EC2 instance is in a different region) you can set the bucket region in the S3 init.

return new aws.S3({region:"s3-eu-west-1"})