我正在尝试在 AWS lambda 上使用 Firefox 运行 puppeteer 以打印 PDF。
我的 AWS Lambda 层:nodejs->node_modules
node_modules 包含 Firefox 二进制文件,因为它在我的本地开发环境中工作。
Lambda 函数:
exports.handler = async (event) => {
const browser = await puppeteer.launch({
product: 'firefox',headless: true
});
const page = await browser.newPage();
await page.goto("http://google.com/");
console.log("loaded");
const response = {
statusCode: 200,body: JSON.stringify('Hello from Lambda!'),};
return response;
};
我得到的错误
{
"errorType": "Error","errorMessage": "Could not find expected browser (firefox) locally. Run `PUPPETEER_PRODUCT=firefox npm install` to download a supported Firefox browser binary.","trace": [
"Error: Could not find expected browser (firefox) locally. Run `PUPPETEER_PRODUCT=firefox npm install` to download a supported Firefox browser binary."," at FirefoxLauncher.launch (/opt/nodejs/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:194:23)"," at async Runtime.exports.handler (/var/task/index.js:8:21)"
]
}
有办法解决吗? Firefox 对我来说非常重要,因为它支持 OpenType SVG 字体。