Created
January 23, 2019 17:56
-
-
Save Nomad-Go/f5789f4d99510972983d4fbcb9ee413f to your computer and use it in GitHub Desktop.
Singed S3 Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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