无服务器框架。Chrome "Error: spawn ETXTBSY"。

问题描述 投票:2回答:1

我开始尝试用node和puppeteer写一个lambda函数。我使用的是无服务器框架

我一直试图按照指示在 https:/github.comalixaxelchrome-aws-lambda。. 我的函数在本机上工作得很正常,有。

$ 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",

"dependencies".{ "chrome-aws-lambda": { { "chrome-aws-lambda": "^3.1.1", "puppeteer-core": "^3.1.0"

}

serverless.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

.....
node.js google-chrome aws-lambda puppeteer serverless-framework
1个回答
3
投票

你可以通过使用下面的命令来删除这个错误:-。

$ npm install --no-bin-links
© www.soinside.com 2019 - 2024. All rights reserved.