puppeteer-cluster icon indicating copy to clipboard operation
puppeteer-cluster copied to clipboard

Would it be possible to run puppeteer-cluster on AWS Lambda?

Open krunalshah68 opened this issue 6 years ago • 18 comments

I have tried running puppeteer-cluster with AWS Lambda Optimised chrome binaries from https://github.com/Kikobeats/aws-lambda-chrome. but running into errors. Is it possible to run cluster on AWS Lamda?

krunalshah68 avatar Nov 19 '18 10:11 krunalshah68

I have not tried it myself, but if you are able to launch two puppeteer instances in parallel, there should be no problems using the library.

What did you try and what errors did you get?

thomasdondorf avatar Nov 20 '18 19:11 thomasdondorf

I've tried to provide chrome executable path from https://github.com/Kikobeats/aws-lambda-chrome and getting this error

 UnhandledPromiseRejectionWarning: Error: Unable to get browser page
    at Worker.<anonymous> (/usr/local/load_test/node_modules/puppeteer-cluster/dist/Worker.js:43:31)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/load_test/node_modules/puppeteer-cluster/dist/Worker.js:4:58)
    at process._tickCallback (internal/process/next_tick.js:68:7)

krunalshah68 avatar Nov 21 '18 10:11 krunalshah68

any update on this @thomasdondorf ?

krunalshah68 avatar Nov 27 '18 11:11 krunalshah68

No. I'm not using this library on AWS Lambda.

In case you want to investigate:

  • Does spawning a normal puppeteer instance work (without this library)?
  • Does spawning two puppeteer instances in parallel work (without this library?
  • What kind of concurrency option are you using?
  • What does your code look like?
  • What output does the debug log produce?

thomasdondorf avatar Dec 21 '18 15:12 thomasdondorf

Hey, @thomasdondorf Thanks for the reply, Actually, I have moved my project to EC2 due to a deadline but will post try and post updates about your questions soon.

krunalshah68 avatar Dec 28 '18 13:12 krunalshah68

Hi @krunalshah68, I would love to know if you've managed to run puppeteer cluster on Lambda

mapi33 avatar Jul 03 '19 20:07 mapi33

I was able to get it working in a lambda with this forked version of puppeteer-cluster: https://github.com/NikolaiT/puppeteer-cluster/ and https://github.com/alixaxel/chrome-aws-lambda

cmaycumber avatar Aug 09 '19 17:08 cmaycumber

Awesome! Thanks, I'll try it out

mapi33 avatar Aug 10 '19 10:08 mapi33

That commit/repo you are linking to does not change anything related to running on AWS, it just adds "per browser options". So, if you got it running on AWS with that repo, I am very positive, that you should be able to get it running with this repository. @cmaycumber Maybe you can share your code?

thomasdondorf avatar Aug 10 '19 14:08 thomasdondorf

Hello,

I've recently discovered this library and I'm using it with AWS Lambda.

That's my configuration:

const { Cluster } = require('puppeteer-cluster')
const HEADLESS = !!process.env.LAMBDA_TASK_ROOT
const REQ_TIMEOUT = 8000

return Cluster.launch({
    concurrency: Cluster.CONCURRENCY_PAGE,
    maxConcurrency: 2,
    puppeteer: isLambda ? require('puppeteer-core') : require('puppeteer'),
    puppeteerOptions: {
      args: [
        ...chromium.args,
        '--disable-web-security',
        '--disable-dev-profile',
        '--font-render-hinting=medium', // could be 'none', 'medium'
        '--enable-font-antialiasing'
      ],
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath,
      headless: HEADLESS,
      timeout: REQ_TIMEOUT,
      userDataDir: '/dev/null'
    }
  })

Also, I'm the author of browserless, a top-level wrapper around puppeteer.

I was thinking could be very great to adopt puppeteer-cluster inside browserless. Right now, I have a generic pool package, but this library is a better solution since you are handling errors, etc.

The premise of browserless is to provide sensible good defaults (e.g., the library has a builtin adblocker by default) so just I need to expose maxConcurrency and concurrency as part of the shared interface and any user can setup a cluster of instances automagically 🙂

Kikobeats avatar Aug 24 '19 16:08 Kikobeats

Nice, thank you for sharing your config.

thomasdondorf avatar Aug 25 '19 19:08 thomasdondorf

Hi @thomasdondorf , I have been able to get puppeteer-cluster running on AW Lmabda with the intrsuctions provided above by @Kikobeats . However it works only when I set the concurrent to Cluster.CONCURRENCY_PAGE. IN the cases of both Cluster.CONCURRENCY_CONTEXT and Cluster.CONCURRENCY_BROWSER , it doesnt seem to work. It looks like the worker(s) are initialized but fails when it trys to get the browser page

puppeteer-cluster: Worker Error getting browser page (try: 5), message: Protocol error (Target.createTarget): Target closed.

I ran the lambda with DEBUG for puppeteer* and here is the log file from running it.

Can you advise on what I might be doing wrong ?

vidyanand avatar Dec 08 '19 22:12 vidyanand

@vidyanand - I'm running into the same problem with Cluster.CONCURRENCY_CONTEXT. Did you ever get this resolved?

deldrid1 avatar Aug 10 '20 13:08 deldrid1

@deldrid1 Nope. I did not. I dont think you can do this with AWS Lambda right now with this package. This article (though not related to pupetter at all) may shed some light on this.

vidyanand avatar Aug 10 '20 13:08 vidyanand

Hi, did anyone succeeded to run this using Cluster.CONCURRENCY_CONTEXT ? I confirm @Kikobeats solution is working fine with Cluster.CONCURRENCY_PAGE

eezdev avatar Apr 15 '21 20:04 eezdev

The same here, it's not working with CONCURRENCY_CONTEXT, any updates on it?

Uchihinha avatar Feb 19 '24 21:02 Uchihinha