Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
AWS Lambda unzip and upload thousands of files

I have 2 S3 buckets. Bucket A is where a zip file gets uploaded to and bucket B contains the extracted data from the latest zip that was uploaded to bucket A. I have a Lambda that triggers upon a object create event from bucket A, it then extracts the zip as a stream and uploads to bucket B. Here is the code:

const aws = require('aws-sdk');
const unzipper = require('unzipper');
const s3Client = new aws.S3({ apiVersion: '2006-03-01' });

exports.handler = async (event, context) => {
    const sourceBucket = event.Records[0].s3.bucket.name;
    const zip = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));

    const s3Params = {
        Bucket: sourceBucket,
        Key: zip
    };

    const zip = s3Client.getObject(s3Params).createReadStream().pipe(unzipper.Parse({ forceStream: true }));
    const promises = [];

    for await (const file of zip) {
        const type = file.type;
        if (type === 'File') {
            const fileName = file.path;

            const params = {
                Bucket: process.env.DEST_BUCKET,
                Key: `${fileName}`,
                Body: file,
            };
            promises.push(s3Client.upload(params).promise());
        } else {
            file.autodrain();
        }
    }
    await Promise.all(promises);
};

The problem is the zip is about 200MB with over 10,000 files and folders in it. The lambda, even set at 900 seconds, is timing out. Is there a more efficient way to write the above code to utilize something like parallel streams or rewriting of the for-loop?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!