api-screenshot icon indicating copy to clipboard operation
api-screenshot copied to clipboard

Chromium 50MB AWS Lambda Node 12 Mega Issue

Open zachleat opened this issue 2 years ago • 4 comments

Spawned from #13. Related to #15.

Ideally we could upgrade the node runtime https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html but newer versions of puppeteer blow past the 50MB AWS Lambda limit. I haven’t tested all versions of Puppeteer to see if there are some that work in Node 14 but don’t hit the 50MB limit yet.

Right now the workaround/requirement is to put an environment variable in your Netlify app UI setting AWS_LAMBDA_JS_RUNTIME to nodejs12.x. This cannot be set via netlify.toml (https://answers.netlify.com/t/netlify-functions-and-env-variables-from-netlify-toml/4404/28)

PR #14 uses the new package from Sparticuz: https://github.com/Sparticuz/chromium/issues/8

There is a hard deadline on this one (March 31, 2023) as Node 12 in AWS is going away: https://aws.amazon.com/blogs/developer/announcing-the-end-of-support-for-node-js-12-x-in-the-aws-sdk-for-javascript-v3/

Related:

  • Build plugin may workaround the netlify.toml issue https://github.com/bencao/netlify-plugin-inline-functions-env#readme
  • https://github.com/puppeteer/puppeteer/blob/da92055e9c187f4d0cce6ca548bc69689c452b6d/docs/troubleshooting.md
  • https://answers.netlify.com/t/chrome-aws-lambda-stopped-working-possibly-due-to-different-version-of-netlify-build/48847
  • https://answers.netlify.com/t/netlify-function-with-puppeteer-breaks-if-i-make-any-changes/76924

zachleat avatar Nov 24 '22 01:11 zachleat

Any updates on this?

aarongustafson avatar Sep 20 '23 19:09 aarongustafson

In case it helps, here's an example to get a screenshot, that works with chromium-min, and puppeteer 18. Using chromium-min is the key here to get smaller deployments.

https://github.com/jaimeiniesta/screenshot-nextjs

The only issue I have is that fullPage: false is not respected and it always returns a full page screenshot. I have a PR to upgrade to puppeteer 19 where the screenshot size works as expected, but it times out in Vercel and I still don't know why.

https://github.com/jaimeiniesta/screenshot-nextjs/issues/9

jaimeiniesta avatar Sep 21 '23 08:09 jaimeiniesta

Am I correct in assuming there's no way to deploy this package as-is to Netlify until this is resolved?

matfantinel avatar Mar 30 '24 17:03 matfantinel

Am I correct in assuming there's no way to deploy this package as-is to Netlify until this is resolved?

That's my experience, yes

aarongustafson avatar Mar 30 '24 20:03 aarongustafson

I've just opened #22 which should allow this to run on the latest Node LTS (20) on Netlify. It's been working for me but if anyone tries it and runs into issues with it please let me know :)

allmarkedup avatar Jul 15 '24 11:07 allmarkedup

I've just opened #22 which should allow this to run on the latest Node LTS (20) on Netlify. It's been working for me but if anyone tries it and runs into issues with it please let me know :)

Hi, I just tried and I confirm it's working. I basically followed what they suggest over here: https://www.blackspike.com/blog/netlify-puppeteer/

countfak avatar Jul 16 '24 10:07 countfak

This should be solved by #22 and #14, thank you @allmarkedup and @LewisDaleUK!

Note also that the production service for this v1.screenshot.11ty.dev is now running on Vercel and the v1-vercel branch is now the primary one that I’ll be maintaining moving forward. As noted in #22, I’m happy to continue to merge PRs to v1-netlify if folks want to help maintain that one.

zachleat avatar Jul 18 '24 00:07 zachleat