Skip to content

Instantly share code, notes, and snippets.

@wolfeidau
Created September 7, 2018 03:11
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 wolfeidau/dc621058795935d5e33d1362fb590915 to your computer and use it in GitHub Desktop.
Save wolfeidau/dc621058795935d5e33d1362fb590915 to your computer and use it in GitHub Desktop.
Lambda endpoint from cmd/raven_lambda folder.
package main
import (
"github.com/apex/gateway"
"github.com/aws/aws-lambda-go/lambda"
log "github.com/sirupsen/logrus"
"github.com/wolfeidau/lambda-raven-service/pkg/api"
"github.com/wolfeidau/lambda-raven-service/pkg/config"
"github.com/wolfeidau/lambda-raven-service/pkg/handlers"
_ "github.com/wolfeidau/lambda-raven-service/pkg/logging"
"github.com/wolfeidau/lambda-raven-service/pkg/store"
)
func main() {
cfg, err := config.New()
if err != nil {
log.WithError(err).Fatal("failed to load configuration")
}
log.WithField("config", cfg).Info("loaded config")
switch cfg.EventHandler {
case "authoriser":
auth := handlers.NewAuthoriser(cfg)
lambda.Start(auth.HandleAuthRequest)
case "event_reciever":
st := store.New(cfg)
ra := handlers.NewRavenAPI(cfg, st)
lambda.Start(gateway.ListenAndServe(":3000", api.NewRouter(ra)))
case "event_aggregator":
auth := handlers.NewEventAggregator(cfg)
lambda.Start(auth.HandleDynamoDBStreamRequest)
default:
log.WithField("EventHandler", cfg.EventHandler).Fatal("failed to locate event handler")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment