chrome-aws-lambda
chrome-aws-lambda copied to clipboard
Error: An \`executablePath\` or \`channel\` must be specified for \`puppeteer-core\` in AWS Lambda using chrome-aws-lambda
I'm encountering an issue when trying to use chrome-aws-lambda
and puppeteer-core
in an AWS Lambda environment. The error message suggests that an executablePath
or channel
must be specified for puppeteer-core
, even though I'm using chrome-aws-lambda
as expected.
Steps to Reproduce:
-
I have the following setup in my Lambda function using
chrome-aws-lambda
andpuppeteer-core
:-
Runtime:
nodejs18.x
-
Memory Size:
2048 MB
-
Timeout:
30 seconds
- I am using the Chrome layer for AWS Lambda (
arn:aws:lambda:ap-south-1:764866452798:layer:chrome-aws-lambda:47
).
-
Runtime:
-
My
serverless.yml
configuration is as follows:
service: auto-pdf-processor
frameworkVersion: "3"
provider:
name: aws
runtime: nodejs18.x
region: ap-south-1
memorySize: 2048
timeout: 30
environment:
IS_OFFLINE: ${opt:isOffline, 'false'}
functions:
server:
handler: src/index.handler
# layers:
# - arn:aws:lambda:ap-south-1:764866452798:layer:chrome-aws-lambda:47
events:
- http:
path: /
method: ANY
cors: true
- The relevant part of my code is as follows:
import puppeteer from 'puppeteer-core';
import chromium from 'chrome-aws-lambda';
export const getChrome = async (url: string) => {
if (process.env.IS_OFFLINE === 'true') {
const chromeExecutablePath = "C:/Program Files/Google/Chrome/Application/chrome.exe";
const browser = await puppeteer.launch({
executablePath: chromeExecutablePath,
headless: true,
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--window-size=1920,1080',
],
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' });
return { browser, page };
} else {
const browser = await puppeteer.launch({
args: chromium.args,
executablePath: await chromium.executablePath,
headless: chromium.headless,
});
const page = await browser.newPage();
await page.goto(url, { waitUntil: 'networkidle0' });
return { browser, page };
}
};
Expected Behavior:
The puppeteer-core
should launch Chrome using chrome-aws-lambda
in the AWS Lambda environment without issues.
Actual Behavior:
The Lambda function throws the following error:
Error: An `executablePath` or `channel` must be specified for `puppeteer-core`
Error Log:
2024-09-09T15:05:43.615Z ERROR Error capturing screenshot: Error: An `executablePath` or `channel` must be specified for `puppeteer-core`
at assert (/var/task/src/index.js:1907:15)
at ChromeLauncher.computeLaunchArguments (/var/task/src/index.js:335930:7)
at async ChromeLauncher.launch (/var/task/src/index.js:335639:24)
at async getChrome (/var/task/src/index.js:336498:21)
Additional Information:
I’ve already included the chrome-aws-lambda
layer in my Lambda function, as well as ensured that all the required dependencies (i.e., chrome-aws-lambda
and puppeteer-core
) are bundled with the deployment.
Versions:
- Node.js: 18.x
- chrome-aws-lambda: 10.1.0
- puppeteer-core: 19.1.0
- OS: win 11
Question:
How can I resolve this issue and ensure that puppeteer-core
uses the chrome-aws-lambda
executable path correctly in the AWS Lambda environment?
Any guidance or suggestions would be much appreciated.