【问题标题】:Aws-lambda-php Process exited before completing requestAws-lambda-php 进程在完成请求之前退出
【发布时间】:2018-05-02 13:28:41
【问题描述】:

错误:生成 php-7-bin/bin/php ENOENT

  process.env['PATH'] = process.env['PATH'] + ':' + 
  process.env['LAMBDA_TASK_ROOT'];

 const spawn = require('child_process').spawn;

 exports.handler = function(event, context) {

   var php = spawn('php-7-bin/bin/php',['helloLambda.php']);
   var output = "";

   //send the input event json as string via STDIN to php process
   php.stdin.write(JSON.stringify(event));

  //close the php stream to unblock php process
  php.stdin.end();

  //dynamically collect php output
  php.stdout.on('data', function(data) {console.log("data",data);
      output+=data;
});

//react to potential errors
php.stderr.on('data', function(data) {
        console.log("STDERR: "+data);
});

//finalize when php process is done.
php.on('close', function(code) {
        context.succeed(JSON.parse(output));
});
}

我尝试给出这些可能的路径:

'php-7-bin/bin/php' (as in doc)<br>
'./php-7-bin/bin/php'<br>
'~/php-7-bin/bin/php'<br>
'/php-7-bin/bin/php'<br>
'php'

这是我关注的文档: https://aws.amazon.com/blogs/compute/scripting-languages-for-aws-lambda-running-php-ruby-and-go/

【问题讨论】:

    标签: php aws-lambda


    【解决方案1】:

    由于错误明确指出“没有这样的目录条目”。 我尝试打印当前工作目录。

    console.log(process.cwd()); /ouptput : 'var/task'.
    

    然后将php路径改为

      var php = spawn('/var/task/php-lambda/php-7-bin/bin/php',['/var/task/php-lambda/helloLambda.php']);
    

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 1970-01-01
      • 2015-08-03
      • 2017-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多