forked from phusion/traveling-ruby-native-extensions-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handler.js
29 lines (24 loc) · 920 Bytes
/
handler.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
var spawn = require('child_process').spawn;
var invokeRubyApp = "./wrapper.sh";
exports.hello = function(event, context, callback) {
const response = {
statusCode: 200,
body: JSON.stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
}),
};
console.log("Starting process: " + invokeRubyApp);
var child = spawn(invokeRubyApp, [JSON.stringify(event, null, 2), JSON.stringify(context, null, 2)]);
child.stdout.on('data', function (data) { console.log("stdout:\n"+data); });
child.stderr.on('data', function (data) { console.log("stderr:\n"+data); });
child.on('close', function (code) {
if(code === 0) {
console.log("Process completed: " + invokeRubyApp);
callback(null, response);
} else {
console.log("Process \"" + invokeRubyApp + "\" exited with code: " + code);
callback(null, response);
}
});
}