Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda