Created
February 22, 2016 02:58
-
-
Save bdenning/41e866febe5f8348bba4 to your computer and use it in GitHub Desktop.
AWS Lambda : Calling golang from python
This file contains 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
## lambda.py | |
import json | |
from sys import argv, stdin, stdout | |
from subprocess import Popen, PIPE | |
def lambda_handler(event, context): | |
proc = Popen('./main', stdin=PIPE, stdout=PIPE) | |
stdout, stderr = proc.communicate(json.dumps(event)) | |
if stderr != None: | |
return json.loads(stderr) | |
return json.loads(stdout) | |
## main.go | |
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
events := bufio.NewScanner(os.Stdin) | |
events.Scan() | |
fmt.Print(events.Text()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ go build main.go
$ zip -r lambda.zip lambda.py main