Skip to content

Instantly share code, notes, and snippets.

@questsin
Created February 20, 2019 15:06
Show Gist options
  • Save questsin/b6e5df541bfd46f30fc8afa81f9d12d1 to your computer and use it in GitHub Desktop.
Save questsin/b6e5df541bfd46f30fc8afa81f9d12d1 to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
//from a s3 trigger
exports.handler = function(event, context, callback) {
// Retrieve the bucket & key for the uploaded S3 object that
// caused this Lambda function to be triggered
var src_bkt = event.Records[0].s3.bucket.name;
var src_key = event.Records[0].s3.object.key;
// Retrieve the object
s3.getObject({
Bucket: src_bkt,
Key: src_key
}, function(err, data) {
if (err) {
console.log(err, err.stack);
callback(err);
} else {
console.log("Raw text:\n" + data.Body.toString('ascii'));
callback(null, null);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment