I am trying to create a task on AWS Lambda that creates a PDF file from PhantomJS and then downloads it to AWS S3 later.
Now I'm trying to run it on Lambda, but it is always Timeout.
My Lambda has 128 MB of ram. Node.js runtime 4.4.3.
This is the error I received from Lambda
"errorMessage": "2017-03-01T08:05:56.255Z dfd4cfe8-fe55-11e6-bf24-e7edf412e037 Task timed out after 10.00 seconds"
This is also the output of the magazine.
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) {
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
var phantomPath = path.join(__dirname, 'phantomjs_linux-x86_64');
var processArgs = [
path.join(__dirname, 'phantom-script.js'),
event.url
];
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;
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();
console.timeEnd("execute time");
});
});
});
});
system.stdout.write('hello from phantom!')
phantom.exit();
I try to do my job after this answer , but it does not work.
I didn’t receive a single magazine from mine phantom-script.js, as if it was not a trigger, but my task is always time.