Reputation: 1098
I'm attempting to use Puppeteer with Lambda, however, on serverless deploy, the lambda errors out due to exceeding the 250mb unbundled package size limit.
So, to get under the limit, I've switched to Puppeteer core which doesn't come packaged with chromium. This requires referencing a path to an executable to launch chrome. (e.g. puppeteer.launch({executablePath: headlessChromiumPath})
);
However, I'm not sure how to load a headless Chromium into my container so that I can later reference it.
To solve this I'm trying a couple of things:
First, I've downloaded a binary headless chromium and I've included it into my API.
File structure:
-run-puppeteer.js
-headless_shell.tar.gz
Referenced like:
const browser = await puppeteer.launch({
executablePath: "../headless_shell.tar.gz"
});
However, I can't import or require it so my lambda doesn't recognize that it exists and doesn't include it in my deployment package. My question here is how do I correctly include the headless file into my API so that I can reference it from within this lambda?
If that isn't an option - I see that I can upload the binary to S3 and then download it on container startup. Any references on where to begin tackling this would be much appreciated.
Upvotes: 6
Views: 9871
Reputation: 469
chrome-aws-lambda
indeed is big ~40MB adding to the deployment package, using Layer could potentially reduce the package size but also could increase the size, because the 250MB unzipped limit includes the layer and the lambda code. If you use chrome-aws-lambda
then definitely do NOT use puppeteer
, instead use puppeteer-core
for a smaller size. I did a very similar setup this hopefully it helps1
Upvotes: 2
Reputation: 1750
You can use chrome-aws-lambda to either package chrome with your Lambda or create a Lambda Layer to avoid the package size.
I did something similar here based on chrome-aws-lambda
Upvotes: 3