apex / apex-go

Golang runtime for Apex/Lambda.
MIT License
293 stars 32 forks source link

Empty event appears in a apex.HandleFunc #43

Closed yarikbratashchuk closed 7 years ago

yarikbratashchuk commented 7 years ago

Hello. I got a problem, and i can't figure out where i go wrong.

apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
 log.Print(event) //returns []
 return HandleEvent(event)
})

So i have empty event, and {"error":"unexpected end of JSON input"} appears. I run function like this: echo '{"link":"https://google.com"}'|go run main.go handler.go Am I doing it wrong?

And I want to mention that it works when it is deployed.

tj commented 7 years ago

Keep in mind HandleFunc() is for interacting with the Node.js shim, so it's actually expecting an .event property:

$ echo '{ "event": { "hello": "foo" }}' | go run _examples/go/functions/simple/main.go 
{"value":{"hello":"foo"}}

Whereas apex invoke does not (but only supports calling the remote lambda currently). For testing locally I just recommend writing libraries / unit tests.

yarikbratashchuk commented 7 years ago

@tj yes, i should have seen it. Thank you.

tj commented 7 years ago

no problem!