title: Serverless framework: Chrome "Error: spawn ETXTBSY",
body: <p>I'm getting started trying to write a lambda function with node and puppeteer. I'm using the serverless framework</p>
  
  <p>I've been trying to follow directions at <a href="https://github.com/alixaxel/chrome-aws-lambda" rel="noreferrer">https://github.com/alixaxel/chrome-aws-lambda</a>. My function is working as expected locally, with:</p>
  
  <pre><code>$ sls invoke local -f hello
  </code></pre>
  
  <p>However when I run:</p>
  
  <pre><code>$ sls invoke -f hello
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>{
  "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)"
  ]
  </code></pre>
  
  <p>How can I get this working?</p>
  
  <p>My handler.js contains:</p>
  
  <pre><code>'use strict';
  var index = require('./index.js');
  
  module.exports.hello = async event =&gt; {
  // var t = async event =&gt; {
    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,
       ......
  </code></pre>
  
  <p>my index.js contains:</p>
  
  <pre><code>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;
  </code></pre>
  
  <p>package.json:</p>
  
  <pre><code>  "license": "ISC",
  </code></pre>
  
  <p>"dependencies": {
      "chrome-aws-lambda": "^3.1.1",
      "puppeteer-core": "^3.1.0"</p>
  
  <pre><code>}
  </code></pre>
  
  <p>serverless.yml:</p>
  
  <pre><code># 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
  
  .....
  </code></pre>