Vinz
Vinz

Reputation: 97

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.

Upvotes: 8

Views: 13508

Answers (2)

berkayln
berkayln

Reputation: 995

I was getting same error when i paste the code to the browser. But to test the url we can use something like Postman with the following configuration:

Simply pasting the url into the path should populate the headers for us. As for the body, select “binary” and browse for an image. When we ready, click “Send”. We should get a 200 OK response and now be able to see our uploaded image in our destination bucket. Unless we’ve changed the key it should be under the name “test.png”.

Upvotes: 0

Titi Wangsa bin Damhore
Titi Wangsa bin Damhore

Reputation: 7199

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.

Upvotes: 12

Related Questions