Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS S3 signed URLs with aws-sdk fails with "AuthorizationQueryParametersError"

I am trying to create a pre-signed URL for a private file test.png on S3. My code:

var AWS = require('aws-sdk'); 

AWS.config.region = 'eu-central-1';

const s3 = new AWS.S3();

const key = 'folder/test.png';
const bucket = 'mybucket';
const expiresIn = 2000; 

const params = {
    Bucket: bucket,
    Key: key,
    Expires: expiresIn,
};
console.log('params: ', params);
console.log('region: ', AWS.config.region);

var url = s3.getSignedUrl('getObject', params);
console.log('url sync: ', url);

s3.getSignedUrl('getObject', params, function (err, urlX) {
    console.log("url async: ", urlX);
});

which returns a URL in the console. When I try to access it, it shows

<Error>
<Code>AuthorizationQueryParametersError</Code>
<Message>
Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.
</Message>
<RequestId>97377E063D0B1D09</RequestId>
<HostId>
6GE7EdqUvCEJis+fPoWR0Ffp2kN9Mlql4gs+qB4uY3hA4qR2wYrImkZfv05xy4XVjsZnRDVN63s=
</HostId>
</Error>

I am totally stuck and would really appreciate some idea on how to solve it.

like image 849
Vinzent Avatar asked Dec 24 '22 16:12

Vinzent


1 Answers

i tested your code. i only made modifications to key and bucket. it works. may i know the aws sdk version you are using and the nodejs version you are using? my test was executed on nodejs 8.1.2 and [email protected].

I was able to reproduce your error when I executed curl.

curl url (wrong) -> <Error><Code>AuthorizationQueryParametersError</Code><Message>Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.</Message>

curl "url" (worked)

if you curl without the double quotes, ampersand is interpreted by the shell as a background process.

Alternatively, you could try pasting the generated link in a browser.

Hope this helps.

like image 192
Titi Wangsa bin Damhore Avatar answered Dec 28 '22 11:12

Titi Wangsa bin Damhore