Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Socket.io with AWS Lambda?

Is it possible to build a function in AWS Lambda that creates a websocket and send data to subscribed applications?

Something like this:

John has the app SuperPhotoApp opened in his phone but decides to use the desktop browser to upload a photo to the SuperPhotoApp service (a S3 Bucket), this event executes a Lambda function that creates a socket.io server and pushes the update to all subscribers, his phone had the app opened so the app automatically updates with the new photo.

This is something that can be done with push notifications or Amazon SNS, but what if I need real-time behaviour for example an online game where I need to update the position of a character.

If this is not possible with Lambda, is there any solution where I can update my opened app using a desktop browser?

Amazon EC2 is the only option? I've read that it has problems with scaling, that's why I'm commenting on Lambda.

like image 574
Vladislav Avatar asked Nov 25 '15 21:11

Vladislav


People also ask

Does AWS support WebSockets?

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.

Is Socket.IO better than WebSocket?

As said before, Socket.IO can fall back to technologies other than WebSockets when the client doesn't support it. If (for some reason) a WebSocket connection drops, it will not automatically reconnect… but guess what? Socket.IO handles that for you! Socket.IO APIs are built to be easier to work with.

What can Socket.IO be used for?

Socket.IO is a JavaScript library for realtime web applications. It enables realtime, bi-directional communication between web clients and server. It has two parts: a client-side library that runs in the browser, and a server-side library for node.


1 Answers

Recently AWS released support of WebSockets for IoT service. It is very easy to use as Pub/Sub message system for serverless web applications. You can post new messages from AWS lambda function via http post request and receive them as websocket messages on a client.

I wrote a small npm package that handles websocket connection to MQTT server from the front-end app. Check out aws-mqtt-client

like image 88
Dmitriy Nevzorov Avatar answered Sep 23 '22 15:09

Dmitriy Nevzorov