Created
March 3, 2017 08:49
-
-
Save juancarloscruzd/321f5304039755968061bf25fc37c169 to your computer and use it in GitHub Desktop.
Lambda delete file from S3 event, useful when you want to parse data from file and destroy evidence.
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
var aws = require('aws-sdk'); | |
var s3 = new aws.S3(); | |
exports.handler = (event, context, callback) => { | |
var srcBucket = event.Records[0].s3.bucket.name; | |
var srcKey = event.Records[0].s3.object.key; | |
// Process file, maybe some CSV parse or image resize, etc. | |
// Delete file | |
var params = { | |
Bucket: srcBucket, | |
Delete: { | |
Objects: [ | |
{ | |
Key: srcKey | |
} | |
], | |
}, | |
}; | |
s3.deleteObjects(params, function(err, data) { | |
if (err) throw error; | |
console.log(data); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment