This content originally appeared on DEV Community and was authored by Kaibalya Kar
Why This Happens
AWS environments (like Amazon Linux 2 on EC2 or Lambda) donβt come with Chromium installed by default. Also, the headless version Puppeteer tries to download is often incompatible with AWS’s OS.
To make Puppeteer work, you need:
A compatible headless Chromium binary.
Proper dependencies installed (fonts, sandbox libs, etc.).
The right launch options.
Why This Happens
AWS environments (like Amazon Linux 2 on EC2 or Lambda) donβt come with Chromium installed by default. Also, the headless version Puppeteer tries to download is often incompatible with AWS’s OS.
To make Puppeteer work, you need:
A compatible headless Chromium binary.
Proper dependencies installed (fonts, sandbox libs, etc.).
The right launch options.
sudo yum update -y
# Install missing libraries
sudo yum install -y \
atk.x86_64 \
cups-libs.x86_64 \
gtk3.x86_64 \
libXcomposite.x86_64 \
libXcursor.x86_64 \
libXdamage.x86_64 \
libXext.x86_64 \
libXi.x86_64 \
libXrandr.x86_64 \
libXss.x86_64 \
libXtst.x86_64 \
pango.x86_64 \
alsa-lib.x86_64 \
ipa-gothic-fonts \
xorg-x11-fonts-100dpi \
xorg-x11-fonts-75dpi \
xorg-x11-utils \
xorg-x11-fonts-cyrillic \
xorg-x11-fonts-Type1 \
xorg-x11-fonts-misc \
wget
Step 2: Download a Compatible Chromium Binary
cd ~
mkdir chromium && cd chromium
wget https://github.com/Sparticuz/chromium/releases/download/v123.0.0/chromium.br
# OR another known working build for Amazon Linux
# Decompress
brew install brotli # if needed
brotli --decompress chromium.br
chmod +x chromium
Step 3: Point Puppeteer to This Chromium
Now in your Node.js code:
import puppeteer from 'puppeteer-core';
const browser = await puppeteer.launch({
executablePath: '/home/ec2-user/chromium/chromium',
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
],
});
Bonus: Using Puppeteer with Chromium in AWS Lambda?
Use chrome-aws-lambda:
npm install puppeteer-core chrome-aws-lambda
Then:
import chromium from 'chrome-aws-lambda';
import puppeteer from 'puppeteer-core';
export const handler = async () => {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless,
});
const page = await browser.newPage();
await page.goto('https://example.com');
const screenshot = await page.screenshot();
await browser.close();
return screenshot;
};
Test It
After setup:
node yourScript.js
If all goes well, Chromium should launch and Puppeteer will work as expected!
Summary
Task Done
Install system dependencies
Download compatible Chromium
Launch Puppeteer with custom binary
Running Puppeteer on AWS isnβt plug and play and but once Chromium is correctly installed and referenced, everything runs smoothly.
This content originally appeared on DEV Community and was authored by Kaibalya Kar