2

I have been working on this feature for work where we need to convert some html into pdf. So I'm using chrome-aws-lambda and puppeteer-core like in the most tutorials anyone can find online. https://medium.com/swlh/how-to-create-pdf-in-lambda-using-puppeteer-6355348b8a82

So when I deployed it to my own AWS with serverless, it works fine, this bit:

 const executablePath = await chromium.executablePath

takes the longest, about 5 seconds, then everything else works as well.

However, the issue arises when I deploy the same code to work's AWS, all of a sudden, this same line of code takes 5 MINUTES

I understand that this executablePath() extracts some binary files from the "chrome-aws-lambda/bin" folder into the "/tmp" folder on Lambda. This is from the node_modules/chrome-aws-lambda/build/index.js :

/**
 * Inflates the current version of Chromium and returns the path to the binary.
 * If not running on AWS Lambda nor Google Cloud Functions, `null` is returned instead.
 */
static get executablePath() {
    if (Chromium.headless !== true) {
        return Promise.resolve(null);
    }
    if (fs_1.existsSync('/tmp/chromium') === true) {
        for (const file of fs_1.readdirSync('/tmp')) {
            if (file.startsWith('core.chromium') === true) {
                fs_1.unlinkSync(`/tmp/${file}`);
            }
        }
        return Promise.resolve('/tmp/chromium');
    }
    const input = path_1.join(__dirname, '..', 'bin');
    const promises = [
        lambdafs_1.default.inflate(`${input}/chromium.br`),
        lambdafs_1.default.inflate(`${input}/swiftshader.tar.br`),
    ];
    if (/^AWS_Lambda_nodejs(?:10|12|14)[.]x$/.test(process.env.AWS_EXECUTION_ENV) === true) {
        promises.push(lambdafs_1.default.inflate(`${input}/aws.tar.br`));
    }
    return Promise.all(promises).then((result) => result.shift());
}

The only difference that I'm aware of between my own AWS account and work's AWS is that work's lambda is hosted on vpc.

So my question is: is being on vpc the cause of the slow extraction from dependency packages?

If so, how does it works? and what can I do to reduce the execution time?

If not, where else should I be looking to find the culprit?

0 Answers0