I am trying to generate PDF invoices using Puppeteer in my Node.js app. Locally, the code works perfectly and generates the PDFs as expected.
However, when I deploy the app to Elastic Beanstalk (Amazon Linux 2023), it fails with an error saying Chrome cannot be found. I tried installing Chrome via .ebextensions but the deployment often hangs or times out.
Here is my PDF generation function:
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');
function fillTemplate(html, data) {
return html.replace(/{{(.*?)}}/g, (_, key) => data[key.trim()] ?? '');
}
async function generateInvoicePDF(filledHtml, outputFileName) {
const browser = await puppeteer.launch({
headless: true,
executablePath: '/usr/bin/google-chrome',
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage'
]
});
const page = await browser.newPage();
await page.setContent(filledHtml, { waitUntil: 'networkidle0' });
const logoBase64 = fs.readFileSync('./public/icon.png', { encoding: 'base64' });
await page.pdf({
path: outputFileName,
format: 'A4',
printBackground: true,
displayHeaderFooter: true,
margin: {
top: '60px',
bottom: '60px',
left: '15mm',
right: '15mm'
}
});
await browser.close();
return outputFileName;
}
And here is my EB config to install Chrome:
# .ebextensions/01_install_chrome.config
commands:
01_install_chrome:
command: "curl https://intoli.com/install-google-chrome.sh | bash"
What I Tried
Installed Chrome using
.ebextensions.Verified that
/usr/bin/google-chromeexists on the instance.Set
executablePathin Puppeteer launch options.
What Happens
Deployment sometimes gets stuck or times out.
Puppeteer cannot find Chrome during PDF generation.
Environment
Node.js v22.18.0
Puppeteer-core latest version
EB platform: Node.js on Amazon Linux 2023
Question
How can I reliably install Google Chrome on Elastic Beanstalk so that Puppeteer can generate PDFs without deployment failures or timing out? I need a solution that works both locally and on EB/EC2, without using curl | bash which causes deployment to hang.