Skip to content

Instantly share code, notes, and snippets.

@rayjanoka
Forked from rayh/example.js
Last active July 19, 2018 04:30
Show Gist options
  • Save rayjanoka/bedb89f8dea086c751bb3e5a75cd8771 to your computer and use it in GitHub Desktop.
Save rayjanoka/bedb89f8dea086c751bb3e5a75cd8771 to your computer and use it in GitHub Desktop.
Spawn binary from AWS Lambda
const spawn = require('./node_modules/child-process-promise/lib').spawn;
process.env["PATH"] = process.env["PATH"] + ":" +
process.env["LAMBDA_TASK_ROOT"];
function spawnCmd(cmd, args, opts) {
var opts = opts||{};
console.log("[spawn]", cmd, args.join(' '), opts);
let cmd_promise = spawn(cmd, args, opts);
let child = cmd_promise.childProcess;
child.stdout.on('data', function(chunk) {
console.log("[" + cmd + ":stdout] " + chunk);
});
child.stderr.on('data', function(chunk) {
console.log("[" + cmd + ":stderr] " + chunk);
});
return cmd_promise;
}
exports.lambda_handler = function(event, context) {
spawnCmd("uname", ["-a"], {
cwd: '/tmp'
}).then(function(result) {
context.succeed(result);
}, function(err) {
context.fail(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment