Using aws-s3-zipper in Lambda

Aws-s3-zipper .
Version: 1.01.
Date: 2016/11/18
Npm src:

I encountered a problem when i tried to use aws-s3-zipper in my lambda function when i used the“zipToS3File” function. This function creates a zip file that is stored in the server as a temporary file and then copied to the S3 bucket.

The problem is that the aws-s3-zipper library zips the chosen files by creating a temporary file located on the server, while Lambda only has one folder (“/tmp/”) that allows to work with files, thus creating issues since the library is not set up to do that.

So, to solve this problem, i modified a lines of code in the index.js file, located in the library module folder (node_modules\aws-s3-zipper\index.js).

zipToS3File is the function that compresses the desired file or folder.

 zipToS3File: function (params, callback) {
if(arguments.length == 4){
 // for backward compatibility
 params = {
 ,recursive: false
 callback= arguments[3];
var t = this;
//I modified the path where the zip file is created, this is the path used to create the file in the server.
params.zipFileName = ‘/tmp/__’ + + ‘.zip’;


So now our aws-s3-zipper is modified to create a zip temporary file in the “/tmp/” folder of lambda and then uploaded to our S3 bucket.

Now we can call the function as follows:

var params = {
 s3FolderName : folder_name,
 s3ZipFileName : s3_tmp_folder + zipFileName,
 recursive : true
zipper.zipToS3File(params, function(err, res)
 callback(null, {status: ‘error’, data: {error: err}});
 callback(null, {status: ‘success’, data: {s3ZipFileSrc: s3_tmp_folder + zipFileName}});
Like what you read? Give Sebastián De la Fuente a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.