title: nodejs: Using child process in aws lambda to run python script not working
body: <p>Using the <a href="https://serverless.com/framework/" rel="nofollow noreferrer">serverless</a> framework and <a href="https://stackoverflow.com/questions/50826884/using-child-process-spawn-on-aws-lambda-for-a-python-script">this</a> post as guide I would like to print out some info from a python script, I have got this relevant code in my handler.js</p>
  
  <pre><code>const path = await require('path')
  const { spawn } = await require('child_process')
  
  /**
   * Run python script, pass in `-u` to not buffer console output 
   * @return {ChildProcess}
   */
  runScript() {
      return spawn('python', [
          "-u",
          path.join(__dirname, 'script.py'),
          "--foo", "some value for foo",
      ]);
  }
  const subprocess = await runScript()
  
  // print output of script
  await subprocess.stdout.on('data', (data) =&gt; {
      console.log(`data:${data}`);
  });
  await subprocess.stderr.on('data', (data) =&gt; {
      console.log(`error:${data}`);
  });
  await subprocess.stderr.on('close', () =&gt; {
      console.log("Closed");
  });
  </code></pre>
  
  <p>and I also have <code>script.py</code></p>
  
  <pre><code>#!/usr/bin/python
  import sys, getopt, time
  
  def main(argv):
      argument = ''
      usage = 'usage: script.py -f &lt;sometext&gt;'
  
      # parse incoming arguments
      try:
          opts, args = getopt.getopt(argv,"hf:",["foo="])
      except getopt.GetoptError:
          print(usage)
          sys.exit(2)
      for opt, arg in opts:
          if opt == '-h':
              print(usage)
              sys.exit()
          elif opt in ("-f", "--foo"):
              argument = arg
  
      # print output
      print("Start : %s" % time.ctime())
      time.sleep( 5 )
      print('Foo is')
      time.sleep( 5 )
      print(argument)
      print("End : %s" % time.ctime())
  
  if __name__ == "__main__":
      main(sys.argv[1:])
  </code></pre>
  
  <p>I am expecting my console to show output or an error when I invoke handler function but it prints nothing</p>