Last active
January 26, 2020 14:38
-
-
Save praveen001/583a8db79f5e53a371c8c6c025e6e62b to your computer and use it in GitHub Desktop.
Serverless WebSockets with API Gateway and Golang Lambda
This file contains 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
// 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