2019-08-12 21:02 阅读 199

为什么AWS API Gateway Websocket发送错误

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 (


func Handler(request events.APIGatewayWebsocketProxyRequest) {
    fmt.Println("default function ran")

func main() {

Probably not super relevant but the serverless.yaml config:

    handler: bin/ws
      - websocket:
          route: $default

The payload I'm sending:

  "action": "whatever",
  "data":  "{whatever}"
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    duanran3115 duanran3115 2019-08-13 08:50

    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)
    点赞 评论 复制链接分享
  • douzhanlai4671 douzhanlai4671 2019-08-13 16:04

    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.

    点赞 评论 复制链接分享