Skip to content

Instantly share code, notes, and snippets.

@juancarloscruzd
Created March 3, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancarloscruzd/321f5304039755968061bf25fc37c169 to your computer and use it in GitHub Desktop.
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.
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