Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless web socket server? [closed]

Are there any serverless technologies that allow a serverless websocket server to be built?

I know the nature of long running connections is that they are stateful, but if the only state is the connection itself at the transport layer then it seems like there could be a serverless product that abstracts this away so you only deal with the application layer. Is there a cloud provider (AWS, Azure, etc) that allows this? I can't see a way for AWS Lambda or Azure Functions to achieve this.

Anyone got any ideas? Just checking.

Thanks

like image 613
ChrisBellew Avatar asked Mar 15 '17 06:03

ChrisBellew


People also ask

Why does WebSocket disconnect?

WebSocket disconnects can happen by choice, or due to exceptional/error conditions. Here is some information about what happens in each case: Clean disconnect: During a clean disconnect, the user or application will initiate a disconnect sequence.

Can I use WebSockets in AWS?

A WebSocket API in API Gateway is a collection of WebSocket routes that are integrated with backend HTTP endpoints, Lambda functions, or other AWS services. You can use API Gateway features to help you with all aspects of the API lifecycle, from creation through monitoring your production APIs.

Does AppSync use WebSockets?

We use AppSync's built-in local resolvers to configure the API to manage multiple ephemeral pub/sub channels and WebSocket connections, automatically delivering and filtering data to subscribed clients based only on the channel name. For the sake of simplicity, API calls are authorized with API keys.

What are WebSockets and Serverless Framework?

Websockets make it possible to add support for a bi-directional communication channel between clients and servers. Connection channels are kept alive and are re-used to exchange messages back-and-forth. The Serverless Framework makes it possible to setup an API Gateway powered Websocket backend with the help of the websocket event.

What is a WebSocket event?

Websocket Websockets make it possible to add support for a bi-directional communication channel between clients and servers. Connection channels are kept alive and are re-used to exchange messages back-and-forth. The Serverless Framework makes it possible to setup an API Gateway powered Websocket backend with the help of the websocket event.

How do I connect to a WebSocket server?

The client establishes a WebSocket connection with HTTP GET request by handshaking process of WebSocket. The request carries an Upgrade header to the server requesting to initiate a WebSocket connection. An important thing to notice that the WebSocket URL uses WS.

Does WebSocket require a dedicated host?

Let’s say that you have an application that uses a Websocket to send and receive data, but it relies on a server that must run on a dedicated host, that is it either needs to live in a container, or run directly on the operating system. This could potentially be a problem if your Websocket server gets a lot of traffic.


2 Answers

With the release of WebSocket support for AWS API Gateway, you can create a server-less WebSocket API.

A WebSocket API is composed of one or more routes. To determine which route a particular inbound request should use, you provide a route selection expression. The expression is evaluated against an inbound request to produce a value that corresponds to one of your route’s routeKey values. API gateway routes the request to corresponding lambda function.
From AWS blog example,
enter image description here

The application is composed of the WebSocket API in API Gateway that handles the connectivity between the client and servers (1). Two AWS Lambda functions react when clients connect (2) or disconnect (5) from the API. The sendMessage function (3) is invoked when the clients send messages to the server. The server sends the message to all connected clients (4) using the new API Gateway Management API. To track each of the connected clients, use a DynamoDB table to persist the connection identifiers (You can also use it to store other state information about the connection).

You can extend this to send messages to clients on any changes to data using DynamoDB Streams

like image 90
Raghava Dhanya Avatar answered Oct 11 '22 08:10

Raghava Dhanya


Fanout can do this. It works as a proxy that can translate WebSocket client activity into a series of HTTP requests. This allows FaaS backends like Lambda to manage raw WebSockets. The function is invoked only when there is activity to react to.

Docs: https://fanout.io/docs/devguide.html#custom-websocket-api

WebSocket-over-HTTP protocol: http://pushpin.org/docs/protocols/websocket-over-http/

Python helper library: https://github.com/fanout/python-faas-grip

like image 44
jkarneges Avatar answered Oct 11 '22 08:10

jkarneges