Using aws-s3-zipper in Lambda

Aws-s3-zipper .
Version: 1.01.
Date: 2016/11/18
Npm src: https://www.npmjs.com/package/aws-s3-zipper

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 = {
 s3FolderName:arguments[0]
 ,startKey:arguments[1]
 ,s3ZipFileName:arguments[2]
 ,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/__’ + Date.now() + ‘.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)
 {
 if(err)
 {
 callback(null, {status: ‘error’, data: {error: err}});
 }
 else
 {
 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.