Go code for a hello.go
file:
package main
import (
"fmt"
"os"
)
func main() {
fmt.Printf("HELLO FROM GOLANG WITH ARGS %v", os.Args)
}
Compile Go binary:
GOOS=linux GOARCH=amd64 go build hello.go
Node Lambda function code for a handler.js
file:
var child_process = require('child_process');
exports.handler = function(event, context) {
var proc = spawn('./hello', [ JSON.stringify(event) ], { stdio: 'inherit' });
proc.on('close', function(code){
if(code !== 0) {
return context.done(new Error("Process exited with non-zero status code"));
}
context.done(null);
});
}
Zip it all up:
zip -r lambda.zip hello handler.js