错误:产生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/
答案 0 :(得分:0)
由于错误明确指出“没有这样的目录条目”。 我尝试打印当前的工作目录。
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']);