Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless framework: Chrome "Error: spawn ETXTBSY",

I'm getting started trying to write a lambda function with node and puppeteer. I'm using the serverless framework

I've been trying to follow directions at https://github.com/alixaxel/chrome-aws-lambda. My function is working as expected locally, with:

$ sls invoke local -f hello

However when I run:

$ sls invoke -f hello

I get:

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

How can I get this working?

My handler.js contains:

'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,
     ......

my index.js contains:

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": "^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

.....
like image 590
user1592380 Avatar asked Jun 06 '20 14:06

user1592380


1 Answers

You can remove this error by using below command:-

$ npm install --no-bin-links
like image 73
kartik tyagi Avatar answered Oct 01 '22 23:10

kartik tyagi