-
-
Save rayjanoka/bedb89f8dea086c751bb3e5a75cd8771 to your computer and use it in GitHub Desktop.
Spawn binary from AWS Lambda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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