vishnumanohar
vishnumanohar

Reputation: 713

AWS lambda puppeteer timed out when creating browser

I am trying to run chromium browser instance inside Lambda using puppeteer and sparticuz/chromium. when I run Lambda gets timed out after 20 secs with 256MB of memory.

The dependencies are created as layer using cloud9 and is included in the lambda.

import chromium from '@sparticuz/chromium';
import puppeteer from 'puppeteer-core';

export const handler = async (event,context) => {

  var exPath=await chromium.executablePath();
  console.log('exPath'+exPath);

    const browser = await puppeteer.launch({
    args: chromium.args,
    defaultViewport: chromium.defaultViewport,
    executablePath: exPath,
    headless: false,
   });
  console.log("----browser created");
};

Response { "errorMessage": "2024-03-02T22:21:20.929Z c4ffd913-d40b-4029-b1f2-91971bbe177d Task timed out after 17.11 seconds" }

Function Logs START RequestId: c4ffd913-d40b-4029-b1f2-91971bbe177d Version: $LATEST 2024-03-02T22:21:20.389Z c4ffd913-d40b-4029-b1f2-91971bbe177d
INFO exPath/tmp/chromium 2024-03-02T22:21:20.929Z c4ffd913-d40b-4029-b1f2-91971bbe177d Task timed out after 17.11 seconds

END RequestId: c4ffd913-d40b-4029-b1f2-91971bbe177d REPORT RequestId: c4ffd913-d40b-4029-b1f2-91971bbe177d Duration: 17110.91 ms Billed Duration: 17000 ms Memory Size: 256 MB Max Memory Used: 256 MB Init Duration: 816.57 ms

Request ID c4ffd913-d40b-4029-b1f2-91971bbe177d

Upvotes: 0

Views: 637

Answers (1)

vishnumanohar
vishnumanohar

Reputation: 713

As @apokryfos suggested the memory required to run the chromium binary was high and increasing it to 512MB resolved the issue.

Update Nov 11 2024:

In my latest AWS Lambda, I had to up the memory even higher (I used 1024 MB). Just launching Chromium with Puppeteer already took 528 MB:

Memory Size: 1024 MB Max Memory Used: 528 MB Init

Upvotes: 1

Related Questions