在Amazon Lambda上运行Spring Boot [英] Running Spring Boot on Amazon Lambda

查看:282
本文介绍了在Amazon Lambda上运行Spring Boot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Amazon Lambda上部署Spring Boot应用程序。
我注意到如果快速连续调用处理程序 - spring尝试重新加载自己,重新设置datsources,重新加载bean等

I am trying to deploy a Spring Boot application on Amazon Lambda. I noticed that if the handler is called in quick succession - spring tries to reload itself, re-setup the datsources, reload beans etc

无论如何都有如果已经调用main方法,告诉Spring Boot不重新初始化?

Is there anyway to tell Spring Boot not to reinitialize itself if the main method has already been called?

谢谢
Damien

Thanks Damien

推荐答案

据我所知,Amazon Lambda是一个无状态函数,可以为每个请求实例化。

As far as I know, a Amazon Lambda is a stateless function, that is instantiated for every request.

如果你多次调用Lambda,很正常,你看到每个请求的Spring Boot初始化。

If you call the Lambda many times, it is quite normal, that you see a Spring Boot initialization for every request.

如果请求缓慢,那么AWS可能会重用再次使用相同的Lambda,因此只进行了一次Spring初始化。

If the requests come slowly, its possible that AWS is reusing the same Lambda again, so only one Spring initialization is done.

如果请求快速或并行,AWS将启动更多Lambdas实例以动态扩展。这解释了你面临的问题。

If the request come fast, or in parallel, AWS will launch more instances of Lambdas to scale dynamically. This explains what you are facing.

我认为,使用整个Spring应用程序作为AWS Lambda并不是正确的方法。 Lambda应该是一个无状态函数,可以快速实例化。

I think, using a whole Spring application as an AWS Lambda is not the right approach. A Lambda should be a stateless function, that can be instantiated quickly.

你可能会尝试让你的spring应用程序尽可能小,以减少加载时间并节省资源,如本教程

You might try to make your spring app as small as possible, to decrease load time and save resources, as explained in this tutorial.

这篇关于在Amazon Lambda上运行Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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