docker – Puppetter on Lambda is running into an ECONNRESET socket hang up

I am running a lambda with puppeteer inside a docker container, all run locally.

Docker container file:


RUN npm install chrome-aws-lambda@10.1.0 puppeteer-core@10.1.0 

CMD [ "app.handler" ]

The code of the lambda is pretty standard: returns the title of the page on success

async function launchBrowser() {
  try { 
    const chromium = require('chrome-aws-lambda');'launching chrome-aws-lambda browser');
    const browser = await chromium.puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath,
      headless: chromium.headless,
      ignoreHTTPSErrors: true,
    return browser;
  } catch (e) { 

async function lambdaHandler(event, context) {
  let result = null;`EVENT ${JSON.stringify(event, null, 2)}`);
  const browser = await launchBrowser();'browser launched');
  const page = await browser.newPage();
  try {
     await page.goto(event.url || '');
    result = await page.title();
  } finally {'finally');
    await page.close();'page closed');
    await browser.close();'browser closed');
  return result;

module.exports = { handler: lambdaHandler };

I am running the container using these 2 commands :

docker build --platform=linux/amd64 -t lambda-aws-based . 
docker run -p 9000:8080 lambda-aws-based

And for testing I am simply invoking the lambda using :

curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"url": ""}'

The thing is on the first call I always run into ECONNRESET socket hang up, only in the calls after does the lambda successfully run, which is an issue for my current use.

So if anyone has an idea how to stop this from happening?
Thank you.

Read more here: Source link