带有会话和数据库的AWS Lambda和Web应用程序 [英] AWS lambda and web application with sessions and databases

查看:143
本文介绍了带有会话和数据库的AWS Lambda和Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正处于开发新的 Web应用程序的初期阶段,并希望利用Amazon云平台.但是,我们可以选择使用Java spring框架或任何其他编程语言/框架来开发Web应用程序.多页应用程序不是无状态的,即一旦登录,应用程序就需要跟踪交易的用户会话.一旦通过多页从用户捕获了所有必需的信息,交易就会提交到数据库.

We are in the very initial phase of developing a new web application and want to make use of Amazon cloud platform. However, we have a choice of developing web applications using Java spring framework or any other programming language/framework. The multipage application is not stateless i.e. application need to keep track of user session for transactions once logged in. Once all the required information is captured from the user through multiple pages, transaction is committed to the database.

但是,我们可能会为此应用程序使用 AWS lambda 服务.使用 AWS Lambda (知道Lambda服务是无会话的)开发具有上述要求的Web应用程序是正确的决定吗?

However, there is a possibility of we using AWS lambda services for this application. Would it be a right decision to develop a web application with the above requirements using AWS Lambda (knowing that Lambda service is sessionless)?

推荐答案

您的问题并非特定于Lambda.会话管理容易(例如可以通过内存或基于文件的存储解决)的唯一情况是在单个服务器环境上.那可能就是你来自哪里.

Your question is not specific to Lambda. The only case where session management is easy (e.g. can be solved by in memory or file based storage) is on a single server environment. That's probably where you're coming from.

当您开始水平扩展时(将更多服务器放入混合服务器中,而不仅仅是向服务器中添加更多RAM/CPU),您需要一个用于会话(以及缓存)的中央存储.如果您在负载均衡器后面选择docker,EC2或什至是金属服务器,也是如此.

The moment you start scaling horizontally (put more servers into the mix opposed to just putting more RAM/CPU into the server) you need a central storage for sessions (and also cache). This is the same if you choose docker, or EC2 or even metal servers behind a load balancer.

这是因为您永远无法确定来自同一用户的下一个请求是否将落在相同的环境上.对于lambda当然也是如此.但是,有一种解决方法:也就是说,如果您使用负载平衡器来使用粘性会话":会将同一用户的每个请求路由到同一台计算机,请参见

This is because you never can tell if the next request from the same user will land on the same environment. That's of course also true for lambda. There's one workaround though: that is, if you use a loadbalancer to use "sticky sessions": this would route every request of the same user to the same machine, see this AWS doc on session management. But sticky session is always suboptimal (e.g. scaling down would mean to destroy sessions) plus for lambda, sticky sessions are not possible afaik.

真正的解决方案(如此处其他答案所示)包括通过Elasticache进行的中央会话存储.以上链接的引言:

The real solution, as the other answers here suggest, includes central session storage via Elasticache. A quote from the above link:

为了解决可伸缩性并为可从任何单个Web服务器访问的会话提供共享数据存储,可以从Web服务器本身抽象HTTP会话.一个常见的解决方案是利用内存中的键/值存储,例如Redis和Memcached.

In order to address scalability and to provide a shared data storage for sessions that can be accessible from any individual web server, you can abstract the HTTP sessions from the web servers themselves. A common solution to for this is to leverage an In-Memory Key/Value store such as Redis and Memcached.

这篇关于带有会话和数据库的AWS Lambda和Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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