Ответ 1
РЕДАКТИРОВАТЬ: это больше не работает. Это очевидное решение.
Вот полный пример кода простого процесса PhantomJS
, который запускается как NodeJS
child_process
. Это также доступно на github.
index.js
var childProcess = require('child_process');
var path = require('path');
exports.handler = function(event, context) {
// Set the path as described here: https://aws.amazon.com/blogs/compute/running-executables-in-aws-lambda/
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
// Set the path to the phantomjs binary
var phantomPath = path.join(__dirname, 'phantomjs_linux-x86_64');
// Arguments for the phantom script
var processArgs = [
path.join(__dirname, 'phantom-script.js'),
'my arg'
];
// Launc the child process
childProcess.execFile(phantomPath, processArgs, function(error, stdout, stderr) {
if (error) {
context.fail(error);
return;
}
if (stderr) {
context.fail(error);
return;
}
context.succeed(stdout);
});
}
Фантомные-script.js
var system = require('system');
var args = system.args;
// Example of how to get arguments passed from node script
// args[0] would be this file name: phantom-script.js
var unusedArg = args[1];
// Send some info node childProcess' stdout
system.stdout.write('hello from phantom!')
phantom.exit();
Чтобы получить бинарный файл PhantomJS, который работает с машинами Amazon Linux, перейдите на страницу Bitbucket PhantomJS и загрузите phantomjs-1.9.8-linux-x86_64.tar.bz2
.