Hey folks, I’m stuck with a tricky situation. I’m working on a TypeScript project that needs to create PDF files. It’s all good on my local machine, but when I try to deploy it to AWS Lambda, it goes over the size limit. So I thought, “Let’s containerize it!”
I managed to get it deployed using Docker, but now I’m hitting a new snag. The app crashes with an error about missing libraries. Here’s what I’m seeing:
let browser = await puppeteer.launch({
headless: false,
args: myArgs,
ignoreDefaultArgs: ['--disable-extensions'],
executablePath: '/usr/bin/chromium-browser',
});
let newPage = await browser.newPage();
I’ve included my Dockerfile, but I’m not sure what I’m missing. Any ideas on how to get Puppeteer playing nice with AWS Lambda in a Docker setup? Thanks in advance for any help!
hey there! i’ve run into similar issues before. have you tried installing the missing libraries in your Dockerfile? you might need to add something like:
RUN apt-get update && apt-get install -y libatk-1.0-0
also, make sure you’re using a compatible base image. alpine-based images can be tricky with puppeteer. good luck!
I’ve encountered this issue before when working with Puppeteer in Docker containers. One solution that worked for me was using the puppeteer-core package instead of the full puppeteer. This approach reduces the overall size and eliminates the need for bundled Chromium.
In your Dockerfile, you’ll need to install Chromium and its dependencies. Here’s a snippet you can add:
As someone who’s deployed Puppeteer in Docker containers on AWS Lambda, I can relate to your frustration. One thing that’s worked well for me is using the amazon/aws-lambda-nodejs base image. It comes pre-configured with most of the libraries Puppeteer needs.
In your Dockerfile, try something like this:
FROM amazon/aws-lambda-nodejs:14
RUN yum install -y amazon-linux-extras
RUN amazon-linux-extras install epel -y
RUN yum install -y chromium
This setup should provide the necessary dependencies without bloating your container too much. Also, make sure you’re using the --no-sandbox flag when launching Puppeteer: