Skip to content

Instantly share code, notes, and snippets.

@mlafeldt
Created October 6, 2017 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlafeldt/abb7473814e9426e8cc1cd7f2b7c7ac2 to your computer and use it in GitHub Desktop.
Save mlafeldt/abb7473814e9426e8cc1cd7f2b7c7ac2 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"log"
"github.com/apex/go-apex"
"github.com/apex/go-apex/sns"
)
type message struct {
Hello string `json:"hello"`
}
func main() {
apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
var snsEvent sns.Event
if err := json.Unmarshal(event, &snsEvent); err != nil {
return nil, err
}
log.Printf("%+v\n", string(event))
log.Printf("%+v\n", snsEvent.Records[0].SNS.Message)
return snsEvent, nil
})
}
@tj
Copy link

tj commented Oct 6, 2017

there's a service-specific handler for each as well https://github.com/apex/go-apex/blob/master/sns/sns.go#L61, does the json part for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment