Created
May 9, 2017 10:58
-
-
Save johnib/20248744716dfe37cc053559541778f9 to your computer and use it in GitHub Desktop.
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
let path = require('path'); | |
let aws = require('aws-sdk'); | |
let s3Client = new aws.S3(); | |
let zlib = require('zlib'); | |
let s3s = require('s3-streams'); | |
const output_bucket = "stackoverflow-bucket"; | |
exports.handler = (event, context, callback) => { | |
context.callbackWaitsForEmptyEventLoop = false; | |
event.Records.forEach(record => { | |
const params = { | |
Bucket: record.s3.bucket.name, | |
Key: record.s3.object.key | |
}; | |
const isGzip = path.extname(params.Key) === ".gz"; | |
let readStream = s3Client.getObject(params).createReadStream(); | |
readStream = isGzip ? readStream.pipe(zlib.createGunzip()) : readStream; | |
writeStream = s3s.WriteStream(s3Client, { Bucket: output_bucket, Key: path.basename(params.Key, ".gz") }); | |
// begins the actual streaming | |
readStream.pipe(writeStream); | |
writeStream.on('end', () => { | |
callback(null, `Handled ${JSON.stringify(params)}`); | |
}); | |
}); | |
}; |
Sorry. That was a really stupid question. Found it here: http://docs.aws.amazon.com/lambda/latest/dg/nodejs-create-deployment-pkg.html
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi John,
this is an absolute beginner question, but maybe you could give me a hint: I try to use your code but it fail because of a missing requirement (s3-streams). Now I was wondering where to get it and where to put it? I'm new to lambda and a bit clueless...THX in advance.