Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid signature - S3 extract #247

Open
bright-stone opened this issue Oct 6, 2021 · 1 comment
Open

Invalid signature - S3 extract #247

bright-stone opened this issue Oct 6, 2021 · 1 comment

Comments

@bright-stone
Copy link

Hey @ZJONSSON,

I'm attempting to extract a zip file uploaded to S3.

The zip file contains a collection of additional zip files with the initial zip files compressed size around 6GB.

This is the code I have below

console.log('Loading function');

var util = require('util')

const aws = require('aws-sdk');

const s3 = new aws.S3({ apiVersion: '2006-03-01' });

const unzipper = require("unzipper");

var mime = require('mime-types');   // the package we need to include to extract the Content-Type for each entry

exports.handler = async (event) => {
    const bucket = 'myBucket';
    const filename = decodeURIComponent(event.Records[0].s3.object.key.replace(/\+/g, ' '));
    const filepath = filename.substring(0, filename.lastIndexOf("/") + 1);
    
        
    const params = {
        Key: filename,
        Bucket: bucket
    };

    const zip = s3
        .getObject(params)
        .createReadStream()
        .pipe(unzipper.Parse({ forceStream: true }));
    
    const promises = [];
    
    let num = 0;
    
    for await (const e of zip) {
        const entry = e;
        const entryName = entry.path;
        
        const type = entry.type;
        if (type === 'File') {
            const entryMimeType = mime.lookup(entryName); // function to use for getting the MIME for each entry extracted
            
            const uploadParams = {
                Bucket: 'myDestBucket',
                Key: filepath + entryName,
                Body: entry,
                ContentType: entryMimeType, // we need to include this line of code to add a Content-Type for each entry extracted
            };
    
            promises.push(s3.upload(uploadParams).promise());
            num++;
        } else {
            entry.autodrain();
        }
    }
    
    await Promise.all(promises);
};

I'm currently getting the following error appearing in cloudwatch

2021-10-06T04:16:04.342Z 6d90f569-0400-453f-b2b6-8ce646a51212 ERROR Invoke Error { "errorType": "Error", "errorMessage": "invalid signature: 0x8d9bc53", "stack": [ "Error: invalid signature: 0x8d9bc53", " at /opt/nodejs/node_modules/unzipper/lib/parse.js:66:26", " at tryCatcher (/opt/nodejs/node_modules/bluebird/js/release/util.js:16:23)", " at Promise._settlePromiseFromHandler (/opt/nodejs/node_modules/bluebird/js/release/promise.js:510:31)", " at Promise._settlePromise (/opt/nodejs/node_modules/bluebird/js/release/promise.js:567:18)", " at Promise._settlePromiseCtx (/opt/nodejs/node_modules/bluebird/js/release/promise.js:604:10)", " at Async._drainQueue (/opt/nodejs/node_modules/bluebird/js/release/async.js:138:12)", " at Async._drainQueues (/opt/nodejs/node_modules/bluebird/js/release/async.js:143:10)", " at Immediate.Async.drainQueues (/opt/nodejs/node_modules/bluebird/js/release/async.js:17:14)", " at processImmediate (internal/timers.js:461:21)" ] }

It does extract a single zip from the initial archive however.

Really hoping you're able to point me in the right direction!

Thanks for your time.

Nick

@turivishal
Copy link

Any update on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants