3

I'm trying to set up a WebSocket API on API Gateway. I'm following the basic tutorial, and I have everything up and running -> Routes for $connect, $disconnect, "test", $default. I am able to connect to the API, store the connectionId in Redis, and retrieve it when accessing from the test route.

The problem is when I try to send back a message from my lambda (single lambda handling all routes). I'm using the following code

 const apigwManagementApi = new AWS.ApiGatewayManagementApi({
    apiVersion: '2018-11-29',
    endpoint: `https://${event.requestContext.domainName}/${event.requestContext.stage}`
});

Then I call

await apigwManagementApi.postToConnection({
        ConnectionId: connectionId,
        Data: `Echo: ${data}`
    }).promise()

This is only called on the "test" route.

All of this is as per their guide. I had to add a patch to be able to make postConnection work, again, as per their tutorial. The problem is when the above method is called I get a Internal Server Error message from the API Gateway and the lambda times out after 3 seconds.

There is very little info on this method. I'm not sure what is causing the internal server error. I have checked the endpoint and the connectionId, both are correct. What am I doing wrong? Any suggestions?

Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
kvnam
  • 1,285
  • 2
  • 19
  • 34

1 Answers1

0

So the problem wasn't the actual lambda but the fact that it wasn't set up in a VPC that had access to the Internet. So if you're lambda has VPC enabled, make sure you it has a NAT gateway and Internet gateway set up.

kvnam
  • 1,285
  • 2
  • 19
  • 34