Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Socket.io in aws lambda functions

I'm using node js with aws lambda functions for my web application. I want to use web socket in my web app. And socket.io is a very famous library for node.js.

But I'm not sure how can I use it in aws lambda. can anyone let me know how to do it, is it possible using lambda functions?

like image 653
Sparsh Pipley Avatar asked Dec 08 '16 13:12

Sparsh Pipley


People also ask

Does AWS lambda support WebSocket?

In this application, we'll be creating an AWS Lambda service that accepts the WebSocket connections coming via API Gateway. The connections and subscriptions to topics are persisted using DynamoDB. We will be using ws for implementing basic WebSocket clients for the demonstration.

Can I use WebSockets in AWS?

While AppSync is a fully managed GraphQL API service, it is possible to implement a simple WebSocket API in the service with little or no GraphQL knowledge in minutes thanks to useful tools such as the AWS CDK and AWS Amplify libraries.

Is Socket.IO same as WebSocket?

Unlike WebSocket, Socket.IO allows you to broadcast a message to all the connected clients.

Can you ssh into Lambda?

with AWS Lambda. In addition, you can use AWS Lambda to connect to your Linux instances by using SSH and run desired commands and scripts at regular time intervals.


2 Answers

Can't use socket.io with lambdas. Lambdas have a limit on time it can be executed, so holding open connection with a client is impossible.

What you can do though is use SNS. Lambdas can publish messages to SNS topics and lambdas can be invoked with SNS.

like image 129
Erndob Avatar answered Sep 29 '22 20:09

Erndob


Workaround exists for this - it's the WebSockets over MQTT in AWS IoT. This way you can execute your Lambda functions from open socket connections.

like image 31
adamkonrad Avatar answered Sep 29 '22 21:09

adamkonrad