I'm try to create a task on AWS Lambda that create PDF file from PhantomJS then upload it AWS S3 later.
Now, I try to run it on Lambda but it's always Timeout.
My Lambda has 128mb of ram. The runtime is node.js 4.4.3.
This is the error I got from Lambda
"errorMessage": "2017-03-01T08:05:56.255Z dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Task timed out after 10.00 seconds"
Also these are the log output
REPORT RequestId: dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Duration: 10000.08 ms Billed Duration: 10000 ms Memory Size: 128 MB Max Memory Used: 29 MB
2017-03-01T08:05:56.255Z dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Task timed out after 10.00 seconds
This is my code.
Index.js
var childProcess = require('child_process');
var path = require('path');
exports.handler = function(event, context, callback) {
// 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'),
event.url
];
// 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);
});
}
phantom-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's name: phantom-script.js
const url = "https://google.com";
system.stdout.write('hello from phantom!');
console.log("task start, target url = " + url);
console.time("execute time");
phantom.create().then(function(ph) {
console.time("create Page");
ph.createPage().then(function(page) {
console.timeEnd("create Page");
console.time("open website");
page.open(url).then(function(status) {
console.timeEnd("open website");
console.time("render as pdf");
page.render('google.pdf').then(function() {
console.timeEnd("render as pdf");
console.log('Page Rendered');
ph.exit();
// send to s3
console.timeEnd("execute time");
});
});
});
});
// Send some info node's childProcess' stdout
system.stdout.write('hello from phantom!')
phantom.exit();
I try to do my work following this answer but it's not working.
I didn't get any of log from my phantom-script.js
like it is not trigger but my task always timeout.