« Back to Index

Go running in Lambda: https://gist.github.com/miksago/d1c456d4e235e025791d and http://blog.0x82.com/2014/11/24/aws-lambda-functions-in-go/ and https://github.com/jasonmoo/lambda_proc for more details

View original Gist on GitHub

Go running in Lambda.md

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