调用lambda函数时,NodeJS和无服务器框架找不到模块“ chrome-aws-lambda”

时间:2019-06-13 10:46:58

标签: node.js puppeteer serverless-framework

我的代码在本地运行时工作正常,在部署之前我已经用npm install chrome-aws-lambda安装了模块,并尝试了chmod -R +r node_modules/,以防出现读取权限错误,但还是没有运气。

我的handler.js代码:

'use strict';
const {getArrayOfPages} = require("./utils"); 
const creds = require("./creds.json"); 

module.exports.hello = async (event, context) => {
  try {
    var browserendpoint = await getArrayOfPages(creds.username, creds.password)
    console.log("DATA: " + browserendpoint)        
  }
  catch(error) {
    // Code that handles any potential errors
    console.log(error)
  }
}

我的getArrayOfPages.js代码:


const sign_in = 'www.example.com/';
const chromium = require('chrome-aws-lambda')

module.exports = async function (username, password) {
  try {
    browser = await chromium.puppeteer.launch({
      args: chromium.args,
      defaultViewport: chromium.defaultViewport,
      executablePath: await chromium.executablePath,
      headless: chromium.headless,
      slowMo: 250, // slow down by 250ms
      userDataDir: "/tmp/" //save session data/cookies to be shared between lambda functions 
    });
    const endpoint = await browser.wsEndpoint();
    const page = await browser.newPage();
    await page.goto(sign_in, { waitUntil: 'networkidle0' })
    // code to login here
    await browser.disconnect()
    return endpoint
  }
  catch (error) {
    // Code that handles any potential errors
    console.log(error)
  }
}

0 个答案:

没有答案