Created
June 17, 2020 14:49
-
-
Save beckyconning/1b30f1e720da7439f9ca21beb8168ba3 to your computer and use it in GitHub Desktop.
Lambda function that writes web-hooks to S3. You will also need to set up an API gateway to trigger this function.
This file contains hidden or 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
var AWS = require('aws-sdk'); | |
var s3 = new AWS.S3(); | |
var uuidv4 = function() { | |
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random() * 16 | 0, | |
v = c == 'x' ? r : (r & 0x3 | 0x8); | |
return v.toString(16); | |
}); | |
} | |
exports.handler = async(event) => { | |
var bucketName = process.env.bucketName; | |
var folderName = process.env.folderName; | |
var key = folderName + "/" + uuidv4(); | |
var params = { Bucket: bucketName, Key: key, Body: JSON.stringify(event) }; | |
return await s3.upload(params).promise(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment