是否可以将 Socket.io 与 AWS Lambda 一起使用? [英] Is it possible to use Socket.io with AWS Lambda?

查看:27
本文介绍了是否可以将 Socket.io 与 AWS Lambda 一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 AWS Lambda 中构建一个函数来创建 websocket 并将数据发送到订阅的应用程序?

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

像这样:

John 在手机中打开了 SuperPhotoApp 应用,但决定使用桌面浏览器将照片上传到 SuperPhotoApp 服务(S3 Bucket),此事件执行 Lambda 函数,该函数创建 socket.io 服务器并推送更新对于所有订阅者,他的手机已打开应用程序,因此应用程序会自动更新新照片.

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.

这可以通过推送通知或 Amazon SNS 来完成,但如果我需要实时行为,例如需要更新角色位置的在线游戏,该怎么办.

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.

如果 Lambda 无法做到这一点,是否有任何解决方案可以让我使用桌面浏览器更新我打开的应用程序?

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

Amazon EC2 是唯一的选择?我读过它在缩放方面存在问题,这就是我评论 Lambda 的原因.

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

推荐答案

我认为 Lambda 不适用于您在此处描述的情况.下面 AWS 论坛的链接指出,Lambda 函数最多只能运行 15 分钟,而且由于您每 100 毫秒的函数运行时收费,这可能会导致成本过高.亚马逊发表评论称,他们已多次听到该请求,因此有兴趣以某种方式允许这样做.

I don't think that Lambda is going to work for the case you described here. The link to the AWS forum below points out that the Lambda function can only run for a maximum of 15 minutes and further since you are charged per 100ms of function runtime this would probably be cost-prohibitive. There is a comment from Amazon saying they've heard the request several times so are interested in some way to allow for this.

https://forums.aws.amazon.com/thread.jspa?threadID=205761

这是一个人的帖子,他似乎在使用 EC2 和 NodeJS 方面取得了很大的成功,但他不得不使用名为 Websockets/ws 的 Socket.io 替代品.

Here is a post from someone who appears to have a good deal of success using EC2 and NodeJS but he had to use an alternative to Socket.io called Websockets/ws.

http://www.jayway.com/2015/04/13/600k-concurrent-websocket-connections-on-aws-using-node-js/

如果您打算在负载均衡器后面运行您的服务器,那么看起来您将有更多的障碍要跳过:

If you plan to run your server behind a load balancer it looks like you are going to have a few more hoops to jump through:

https://web.archive.org/web/20160118124227/http://coding-ceo.ghost.io/how-to-run-socket-io-behind-elb-on-aws

这篇关于是否可以将 Socket.io 与 AWS Lambda 一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆