node.js - Nodejs AWS SDK S3 Generate Presigned URL -
i using nodejs aws sdk generate presigned s3 url. docs give example of generating presigned url.
here exact code (with sensitive info omitted):
const aws = require('aws-sdk') const s3 = new aws.s3() aws.config.update({accesskeyid: 'id-omitted', secretaccesskey: 'key-omitted'}) // tried , without this. since s3 not region-specific, don't // think should necessary. // aws.config.update({region: 'us-west-2'}) const mybucket = 'bucket-name' const mykey = 'file-name.pdf' const signedurlexpireseconds = 60 * 5 const url = s3.getsignedurl('getobject', { bucket: mybucket, key: mykey, expires: signedurlexpireseconds }) console.log(url)
the url generates looks this:
https://bucket-name.s3-us-west-2.amazonaws.com/file-name.pdf?awsaccesskeyid=[access-key-omitted]&expires=1470666057&signature=[signature-omitted]
i copying url browser , getting following response:
<error> <code>nosuchbucket</code> <message>the specified bucket not exist</message> <bucketname>[bucket-name-omitted]</bucketname> <requestid>d1a358d276305a5c</requestid> <hostid> bz2oxmzcem2173kxedbkizrlx508qsv+cvydhz3w6ffpfwc0ctaca/tqdqydmhqdi1omlc07wwk= </hostid> </error>
i know bucket exists. when navigate item via aws web gui , double click on it, opens object url , works fine:
https://s3-us-west-2.amazonaws.com/[bucket-name-omitted]/[file-name-omitted].pdf?x-amz-date=20160808t141832z&x-amz-expires=300&x-amz-algorithm=aws4-hmac-sha256&x-amz-signature=[signature-omitted]&x-amz-credential=asiajkxdbr5cw3xxf5vq/20160808/us-west-2/s3/aws4_request&x-amz-signedheaders=host&x-amz-security-token=[really-long-key]
so led believe must doing wrong how i'm using sdk.
dustin,
your code correct, double check following:
your bucket access policy.
your bucket permission via api key.
your api key , secret.
your bucket name , key.
Comments
Post a Comment