无服务器框架:Chrome“错误:产生ETXTBSY”,

时间:2020-06-06 14:54:08

标签: node.js google-chrome aws-lambda puppeteer serverless-framework

我开始尝试用node和puppeteer编写lambda函数。我正在使用无服务器框架

我一直在尝试遵循image of update link上的指示。我的功能在本地按预期工作,

select v.*
from v
where not exists (select 1
                  from v_s join
                       f_s
                       on v_s.s_fk = f_s.s_fk join
                       f
                       on f_s.f_fk = f.f_id
                  where f.f_code = 'A' and vs.v_fk = v.v_id
                 );

但是当我跑步时:

$ sls invoke local -f hello

我得到:

$ sls invoke -f hello

我该如何工作?

我的handler.js包含:

{
"errorType": "Error",
"errorMessage": "spawn ETXTBSY",
"trace": [
    "Error: spawn ETXTBSY",
    "    at ChildProcess.spawn (internal/child_process.js:407:11)",
    "    at Object.spawn (child_process.js:548:9)",
    "    at Launcher.launch (/opt/nodejs/node_modules/puppeteer-core/lib/Launcher.js:132:40)",
    "    at async Object.main (/var/task/index.js:50:15)",
    "    at async module.exports.hello (/var/task/handler.js:6:13)"
]

我的index.js包含:

'use strict';
var index = require('./index.js');

module.exports.hello = async event => {
// var t = async event => {
  var res = await index.main();

  console.log('hello');
  console.log(res);

  console.log('IN HANDLER');
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'main function executed!',
        input: event,
     ......

package.json:

async function main(event, context, callback) {

  const os = require('os');

  let result = null;
  let browser = null;

if (os.platform=='win32') {

  const puppeteer= require('puppeteer-core');
  browser = await puppeteer.launch({
    executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
    headless: false,
    ignoreHTTPSErrors:true
  })
} else {
// launch a headless browser

  const chromeLambda = require('chrome-aws-lambda');
console.log(os.platform());  
console.log('lambda');  
browser = await chromeLambda.puppeteer.launch({
    args: chromeLambda.args,
    executablePath: await chromeLambda.executablePath,
    defaultViewport,
    headless:true 
  });





  var page = await browser.newPage();

   ........

};


module.exports.main = main;

“依赖项”:{ “ chrome-aws-lambda”:“ ^ 3.1.1”, “ puppeteer-core”:“ ^ 3.1.0”

  "license": "ISC",

serverless.yml:

}

1 个答案:

答案 0 :(得分:2)

您可以使用以下命令删除此错误:-

$ npm install --no-bin-links