2 Answers
- Newest
- Most votes
- Most comments
0
This method signature works. Would love some more docs/examples using golang. I have yet to successfully send a message through the socket.
type Response events.APIGatewayProxyResponse
func Handler(context context.Context, request events.APIGatewayWebsocketProxyRequest) (Response, error)
answered 5 years ago
0
Hey NateN, not sure if you've figured this out, but I think I have a working solution for now?
I have one struct that I unmarshal the request body to EVERY TIME, no matter what the websocket action is (aside from connect/diconnect)
type WebSocketRequest struct {
Action string `json:"action"`
Data json.RawMessage `json:"data"`
}
webSocketRequest := &models.WebSocketRequest{}
if err := json.Unmarshal([]byte(request.Body), webSocketRequest); err != nil {
return payloads.GenerateErrorResponse(500, err), nil
}
Then for the sendMessage lambda from the example they have, I use this request struct
type sendMessageRequest struct {
Message string `json:"message"`
}
sendMessageRequest := &sendMessageRequest{}
if err := json.Unmarshal(webSocketRequest.Data, sendMessageRequest); err != nil {
return payloads.GenerateErrorResponse(500, err), nil
}
And here is my test message
{"action":"sendmessage","data":{"message":"sending a ws message to you! <3"}}
Hope this helps
answered 5 years ago
Relevant content
- asked 4 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago