繁体   English   中英

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

[英]Serverless framework: Chrome “Error: spawn ETXTBSY”,

我开始尝试使用节点和 puppeteer 编写 lambda function。 我正在使用无服务器框架

我一直在尝试遵循https://github.com/alixaxel/chrome-aws-lambda的指示。 我的 function 在本地按预期工作,其中:

$ sls invoke local -f hello

但是,当我运行时:

$ sls invoke -f hello

我得到:

{
"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)"
]

我怎样才能得到这个工作?

我的 handler.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,
     ......

我的 index.js 包含:

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;

package.json:

  "license": "ISC",

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

}

无服务器.yml:

# Welcome to Serverless!
#
.......
# Happy Coding!
plugins:
  - serverless-offline
service: xxxxx
# app and org for use with dashboard.serverless.com
app: yyyyy
org: xxxx

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
  name: aws
  runtime: nodejs12.x
  region: us-east-1
  # here we put the layers we want to use
  layers:
    # Google Chrome for AWS Lambda as a layer
    # Make sure you use the latest version depending on the region
    # https://github.com/shelfio/chrome-aws-lambda-layer
    - arn:aws:lambda:us-east-1:764866452798:layer:chrome-aws-lambda:10
  # function parameters

# you can overwrite defaults here
#  stage: dev
#  region: us-east-1

.....

functions:
  hello:
    handler: handler.hello
  # main:
    # handler: handler.main
#    The following are a few example events you can configure
#    NOTE: Please make sure to change your handler code to work with those events
#    Check the event documentation for details
    events:
     - http:
         path: hello/get
         method: get

.....

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

$ npm install --no-bin-links

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM