Created
October 5, 2018 09:53
-
-
Save hectorgool/c047bdf4793f0cd62fbe1ac684773545 to your computer and use it in GitHub Desktop.
Lambda functions in a local development environment
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
//_LAMBDA_SERVER_PORT=3000 go run main.go | |
package main | |
import ( | |
"encoding/json" | |
"github.com/aws/aws-lambda-go/lambda" | |
) | |
type Data struct { | |
A, B int64 | |
} | |
func suma(a, b int64) int64 { | |
return a + b | |
} | |
func handler(in interface{} ) (int64, error) { | |
var d Data | |
raw := []byte(in.(string)) | |
if err := json.Unmarshal(raw, &d); err != nil { | |
panic(err) | |
} | |
return suma(d.A, d.B), nil | |
} | |
func main() { | |
lambda.Start(handler) | |
} |
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
package main | |
import ( | |
"fmt" | |
"log" | |
"github.com/davecgh/go-spew/spew" | |
"github.com/djhworld/go-lambda-invoke/golambdainvoke" | |
) | |
func main() { | |
jsondata := `{ | |
"a": 2, | |
"b": 3 | |
}` | |
response, err := golambdainvoke.Run(3000, jsondata) | |
if err != nil { | |
spew.Dump(err) | |
log.Fatal(err) | |
} | |
fmt.Println(string(response)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment