Reputation: 989
I am currently working on an AWS Lambda that generates a PDF from HTML. The lambda is working perfectly once deployed however I would like to get it to run locally to make development easier.
I have installed SAM from AWS as well as Docker which AWS says will be needed to run a lambda locally.
In my solution folder in the command line I am running sam local invoke "HelloWorldFunction" -e pdf/test-data/test.json
which then appears to work as it says that it is fetching it and then mounting it to the local docker container. However it then gives the following error:
Which appears to be an error about the puppeteer executable for chrome not existing even though it is in there. I am using the following variables:
const chromium = require("chrome-aws-lambda");
const puppeteer = require('puppeteer');
const pptr = require('puppeteer-core');
and then the code I am using to start the browser is the following:
const executablePath = event.isOffline
? "./node_modules/puppeteer/.local-chromium/win64-737027/chrome-win/chrome.exe"
: await chromium.executablePath;
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: executablePath,
headless: chromium.headless
});
I have tried the settings given in the puppeteer troubleshooting, reinstalling my packages but nothing seems to work. My packages are also the following versions:
I haven't worked with docker before so I am not sure if that could be the problem? Thanks in advance for any help.
Upvotes: 0
Views: 3555
Reputation: 989
It looks like I had to use the path provided by chrome-aws-lambda
. So the code to generate the browser looks like this and it works:
browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless
});
Upvotes: 1