Skip to content

Instantly share code, notes, and snippets.

@leonmax
Created March 9, 2015 16:30
Show Gist options
  • Save leonmax/d80dd3dced6d36ec672c to your computer and use it in GitHub Desktop.
Save leonmax/d80dd3dced6d36ec672c to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
var getUrl = function(bucket, path, callback) {
var params = {Bucket: bucket, Key: path};
s3.getSignedUrl('getObject', params, callback);
}

to make this work, first:

npm install aws-sdk

then export your s3 key to environment variable

export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE
export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY_HERE

and then just call the above function like this:

getUrl("help-center", "files/1x1_wallpaper_bundle.zip", function (err, url) {
// make a response here and set: STATUS=302, LOCATION=url
});
@leonmax
Copy link
Author

leonmax commented Mar 9, 2015

a tutorial to use pre-signed url to get s3 object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment