Skip to content

Instantly share code, notes, and snippets.

@Nomad-Go
Created January 23, 2019 17:56
Show Gist options
  • Save Nomad-Go/f5789f4d99510972983d4fbcb9ee413f to your computer and use it in GitHub Desktop.
Save Nomad-Go/f5789f4d99510972983d4fbcb9ee413f to your computer and use it in GitHub Desktop.
Singed S3 Lambda
'use strict';
console.log('Loading function');
const aws = require('aws-sdk');
const s3 = new aws.S3({signatureVersion: 'v4'});
exports.handler = (event, context, callback) => {
const bucket = process.env.S3_BUCKET_NAME;
const requestBody = JSON.parse(event.body);
console.log(requestBody);
const key = requestBody["object_key"];
console.log(key);
const params = {Bucket: bucket, Key: key, Expires: 10};
s3.getSignedUrl('putObject', params, (error, url) => {
if (error) {
callback(error);
}else{
var responseBody = {
"URL": url
};
var response = {
"statusCode": 200,
"body": JSON.stringify(responseBody)
};
callback(null, response);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment