简体   繁体   中英

SignatureDoesNotMatch error when performing get request on URL from AWS S3 getSignedUrl in Node.js

Im trying to access data I put using the getSignedUrl method from AWS.S3 API http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#getSignedUrl-property . When I use the url returned by the method I get an error.

Code for putting data in S3 bucket

    var params = {
      Bucket: BUCKET_NAME,
      Key: 'testing132',
      Body: 'tasdfasfasdfs',
      Expires: EXPIRATION_TIME,
      ACL: 'public-read'
    };

    $log.info('test s3 dep', this);

    s3.getSignedUrl('putObject', params, function (err, url) {
      if (err) return cb(err);
      return cb(null, url);
    });

When performing GET request from POSTMAN on the returned URL I receive the following page with some info removed for security

<?xml version="1.0" encoding="UTF-8"?>
<Error>
    <Code>SignatureDoesNotMatch</Code>
    <Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
    <AWSAccessKeyId>ASIAJ.....</AWSAccessKeyId>
    <StringToSign>GET


1467833494
x-amz-acl:public-read
x-amz-security-token:FQoDYXdzEKz//////////wEaDBW+iL+gqGBqn2qxcyKcA1etzJzOZV33H3ND2hxQcm5MsJuZiHuEz5EvODXvDD7IfnlsbgNmLs70WAJ.................=
/s3test_test/testing132</StringToSign>
    <SignatureProvided>sNNramN6fDo+sf......=</SignatureProvided>
    <StringToSignBytes>47 45 54 0a 0a 0a 31 34 36 37 38 33 33 34 39 34 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 75 62 6c 69 63 2d 72 65 61 64 0a 78 2d 61 6d 7a 2d 73 65 63 75 72 69 74 ..............</StringToSignBytes>
    <RequestId>2404FC0B........</RequestId>
    <HostId>u5CapGu...............=</HostId>
</Error>

So there was some confusion, I didn't read the documentation carefully enough. I assumed that the 'putObject' argument in getSignedUrl method mean that I was uploading an object to the specified key and then retrieving a url to that object. This assumption was wrong, basically the putObject parameter means that your specifying the characteristics of an object that the user is PUTTING to the generated url. Using getObject solved the problem. From docs You can use this functionality [putObject] to generate pre-signed PUT operations that require a specific payload to be uploaded by the consumer of the URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM