I am using serverless framework to set up an AWS API Gateway websocket which calls a lambda function written in Go. Right now the handler only logs a message. I can connect to the websocket, and I can see the message is logged in Cloudwatch when I send a message through the socket, but I always get an error message that looks like
{
"message": "Internal server error",
"connectionId": "eU3C1cE7CYcCJPw=",
"requestId": "eU3EQFX0iYcFysQ="
}
There are no errors logged for the lambda in Cloudwatch. The AWS API Gateway config looks good to me. I'm at a loss trying to think of what could cause this.
My main.go:
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func Handler(request events.APIGatewayWebsocketProxyRequest) {
fmt.Println("default function ran")
}
func main() {
lambda.Start(Handler)
}
Probably not super relevant but the serverless.yaml config:
functions:
websocket-default:
handler: bin/ws
events:
- websocket:
route: $default
The payload I'm sending:
{
"action": "whatever",
"data": "{whatever}"
}
Not sure if this is the only problem in your code, but your handler signature should be one listed in the doc:
func ()
func () error
func (TIn) error
func () (TOut, error)
func (context.Context) error
func (context.Context, TIn) error
func (context.Context) (TOut, error)
func (context.Context, TIn) (TOut, error)
Alright so it took a lot of trial and error but this is the method signature that works
type Response events.APIGatewayProxyResponse
func Handler(context context.Context, request events.APIGatewayWebsocketProxyRequest) (Response, error)
I really wish the documentation for golang was better. Thanks to Clement for pointing me in the right direction.