1 Risposta
- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
0
The chrome-aws-lambda module is now deprecated and has been replaced with the chromium package (https://www.npmjs.com/package/@sparticuz/chromium).
Here is an example that works with sam local invoke
- Ensure you have SAM and required pre-reqs installed: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started.html
- Initialize a "hello world" project using the sam CLI. Select node version 18.x for this project
- In the newly created directory for the project, install puppateer
npm install puppeteer-core@19.8.0
- Install chromium
npm install @sparticuz/chromium@112.0.2
- Copy the below sample into app.mjs, replacing the original hello world code
- Sometimes this function will take more than 10 seconds to run. Update the timeout in template.yaml
Timeout: 13
- Run sam build
sam build
- Run locally
sam local invoke
Sample Code for app.mjs:
import chromium from "@sparticuz/chromium";
import puppeteer from "puppeteer-core";
export const lambdaHandler = async (event, context) => {
console.log("starting...");
try {
const browser = await puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath(),
headless: chromium.headless,
});
const page = await browser.newPage();
await page.goto("https://example.com");
const pageTitle = await page.title();
console.log(pageTitle);
} catch (error) {
console.log(error);
}
};
The Chromium package provides an example for running with a Lambda Layer: https://github.com/Sparticuz/chromium/tree/master/examples/serverless-with-lambda-layer
con risposta 9 mesi fa
Contenuto pertinente
- AWS UFFICIALEAggiornata 4 mesi fa
- AWS UFFICIALEAggiornata 2 anni fa
This is not actually a problem with aws lambda but there are others having same problem with chrome-aws-lambda
are you using the lambda layers for that ? https://github.com/shelfio/chrome-aws-lambda-layer