Websocket connection between two servers with one server as lambda

Viewed 137

I want to setup a websocket communication between two servers - Server A & Server B. Server A will receive messages from user application, Server A will process the message and route the message to Server B. Server B will process the message and return the response back to A. A will return the response to user application.

I want to reduce the communication time between Server A & B so I decided to use Websockets for this usecase. But the issue with this is that server A is a lambda so the connection will be destroyed when lambda goes back to idle state.

Is there anyway we can cache the connection data from lambda somewhere and re-use it once we receive the request again?

I know this is may be a little weird question but any suggestions or help will be appreciated :)

A breif on why we are stuck with Lambda and where we can cache connection data:

I am building a chat application with Amazon Lex. Lex provides support for integration with Lambda. We can use the lex session storage to store any attributes we want. For each customer input lex calls lambda(server A) and lambda will call another server B.

2 Answers

Perhaps take a look at the project linked below that makes use of Websockets for a web chat application.

It is built on AWS components so should provide you with a good start. This application is user-to-user but you should be able to easily extend it to provide you with a sufficient base to work from. https://github.com/danilop/serverless-chat

As stated here on: Amazon API Gateway quotas and important notes,

  • Connection duration for WebSocket API is 2 hours,
  • Idle Connection Timeout is 10 minutes,

and they cannot be increased.

Lambdas are for short-lived requests; if you require something available 24/7, you'll need a server. EC2 instance, for example. I'm in the same boat also, and I haven't found a better alternative yet.

Related