Running puppeteer with Firefox on AWS Lambda

Solution for Running puppeteer with Firefox on AWS Lambda
is Given Below:

I’m trying to run puppeteer with Firefox on AWS lambda for printing PDFs.

My AWS Lambda Layer: nodejs->node_modules

node_modules contains Firefox binaries, as it works in my local dev environment.

Lambda Function:


exports.handler = async (event) => {
    const browser = await puppeteer.launch({
    product: 'firefox',
    headless: true
  });
  
  const page = await browser.newPage();
  await page.goto("http://google.com/");
  console.log("loaded");
  
    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

The error that I get

{
  "errorType": "Error",
  "errorMessage": "Could not find expected browser (firefox) locally. Run `PUPPETEER_PRODUCT=firefox npm install` to download a supported Firefox browser binary.",
  "trace": [
    "Error: Could not find expected browser (firefox) locally. Run `PUPPETEER_PRODUCT=firefox npm install` to download a supported Firefox browser binary.",
    "    at FirefoxLauncher.launch (/opt/nodejs/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:194:23)",
    "    at async Runtime.exports.handler (/var/task/index.js:8:21)"
  ]
}

Is there a way to fix it? Firefox is super important for me since it supports OpenType SVG fonts.