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

查看:164
本文介绍了是否可以将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),此事件执行创建socket.io的Lambda函数服务器并将更新推送给所有订阅者,他的手机已打开应用程序,因此应用程序会自动使用新照片进行更新。

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.

这可以通过推送通知完成或亚马逊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函数最多只能运行5分钟,而且由于每100毫秒的函数运行时收费,这可能会成本过高。亚马逊有一条评论说他们已多次听到这个请求,所以有兴趣以某种方式允许这个。

I don't think that Lambda is going to work for the case you describe. The link to the AWS forum below points out that the Lambda function can only run for a maximum of 5 mintues 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似乎取得了很大成功的人的帖子,但他不得不使用Socket.io的替代方案,称为Websockets / ws。

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're 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天全站免登陆