Skip to content

Instantly share code, notes, and snippets.

@johnib
Created May 9, 2017 10:58
Show Gist options
  • Save johnib/20248744716dfe37cc053559541778f9 to your computer and use it in GitHub Desktop.
Save johnib/20248744716dfe37cc053559541778f9 to your computer and use it in GitHub Desktop.
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)}`);
});
});
};
@mikr0012
Copy link

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