Skip to content

Instantly share code, notes, and snippets.

@praveen001
Last active January 26, 2020 14:38
Show Gist options
  • Save praveen001/583a8db79f5e53a371c8c6c025e6e62b to your computer and use it in GitHub Desktop.
Save praveen001/583a8db79f5e53a371c8c6c025e6e62b to your computer and use it in GitHub Desktop.
Serverless WebSockets with API Gateway and Golang Lambda
// Handler is the base handler that will receive all web socket request
func Handler(request APIGatewayWebsocketProxyRequest) (interface{}, error) {
switch request.RequestContext.RouteKey {
case "$connect":
return Connect(request)
case "$disconnect":
return Disconnect(request)
default:
return Default(request)
}
}
func main() {
lambda.Start(Handler)
}
// GetSession creates a new aws session and returns it
func GetSession() *session.Session {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-east-1"),
})
if err != nil {
log.Fatalln("Unable to create AWS session", err.Error())
}
return sess
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment