-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrun-tmpl.js
37 lines (29 loc) · 1.13 KB
/
run-tmpl.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const spawn = require('child_process').spawn;
/**
* handler for AWS Lambda
*/
exports.handle = function(event, context, callback) {
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT']
// help resolve dynamic libraries packaged with function
process.env['LD_LIBRARY_PATH'] = process.env['LAMBDA_TASK_ROOT']
const main = spawn('./$$main$$', { stdio: ['pipe', 'pipe', process.stderr] });
main.stdout.on('data', function(data) {
console.log('stdout: ' + data);
});
main.on('close', function(code) {
console.log('child process pipes closed with code '+ code);
});
console.log("sending data to $$main$$:\n" + JSON.stringify(event));
console.log("$$main$$ pid is " + main.pid);
main.on('exit', function(code){
callback(null, 'child process exited with code ' + code);
});
main.on('error', function(err) {
console.error('error: ' + err);
callback(err, 'child process exited with error: ' + err);
});
main.stdin.write(JSON.stringify({
'event': event,
'context': context
}) + '\n');
}