Struggling to set up Puppeteer on AWS Lambda

Hey everyone, I’m at my wit’s end here!

I’ve been trying to get Puppeteer working on AWS Lambda for the past couple of weeks, but no luck so far. I’ve looked at different starter kits and experimented with several code tweaks, yet nothing seems to work.

Here’s my current setup:

  • Windows 7
  • Node.js 8.10 runtime
  • 3008 MB memory
  • 30-second timeout
  • Using the lambda_basic_execution role (also attempted with a custom role providing full Lambda and S3 access)

I’ve adjusted the package.json scripts to suit my Windows environment and tried various versions of Puppeteer and Chromium. A suggestion to use Puppeteer 1.1.1 didn’t resolve the issue either.

The error message I keep encountering is:

{
    "errorMessage": "Failed to launch chrome! spawn /tmp/headless_shell ENOENT",
    "errorType": "Error",
    "stackTrace": [
        // ... truncated for brevity
    ]
}

I’m deploying my code via Amazon S3 since both the UI and CLI upload methods time out. Any insights or suggestions on how I might fix this would be greatly appreciated!

I’ve faced similar challenges with Puppeteer on AWS Lambda. The key is using puppeteer-core instead of the full Puppeteer package, and pairing it with chrome-aws-lambda. This combination keeps you under the 50MB deployment limit and provides the necessary dependencies.

For your setup, ensure you’re using Node.js 10.x or later, as older versions can cause compatibility issues. Increase your Lambda’s memory to at least 512MB, and consider extending the timeout to 60 seconds for complex operations.

The error you’re seeing suggests the Chromium executable isn’t found. Double-check your code to ensure you’re specifying the correct path to the Chromium executable provided by chrome-aws-lambda.

If issues persist, you might want to look into playwright-aws-lambda as an alternative. It’s gained traction for its compatibility with newer Node.js versions and easier setup process on Lambda.

my suggestion: swap full puppeteer for puppeteer-core with chrome-aws-lambda.

using node 10.x+ and upping memory to 512MB+ could help. the error hints at a missing chromium executable.

double-check your executablePath. if that fails, consider trying playwright-aws-lambda.

Hey Grace, I feel your pain! I’ve been down that Puppeteer-Lambda rabbit hole too. Here’s what finally worked for me:

Ditch the full Puppeteer package and go for puppeteer-core paired with chrome-aws-lambda. This combo keeps you under that pesky 50MB limit and brings all the needed bits.

Bump up to Node.js 10.x or later - older versions can be a real headache. Also, crank that memory to at least 512MB and maybe stretch the timeout to 60 seconds if you’re doing complex stuff.

That error you’re seeing? Classic case of ‘Where’s Waldo?’ but with Chromium. Double-check you’re pointing to the right Chromium executable from chrome-aws-lambda.

If you’re still pulling your hair out, give playwright-aws-lambda a shot. Some folks swear by it for easier Lambda setups.

Hope this helps! Let us know how it goes.