Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Spring Boot on Amazon Lambda

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

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

Thanks Damien

like image 835
Damien Gallagher Avatar asked Apr 07 '17 22:04

Damien Gallagher


People also ask

Is Lambda good for Microservices?

PRO TIP: AWS Lambda is not a microservice. It is a serverless computing platform that allows you to run code without provisioning or managing servers. While AWS Lambda can be used to create small functions, it is not a microservice architecture.

Can we use AWS Lambda for Microservices?

An API created with Amazon API Gateway, and functions subsequently launched by AWS Lambda, is all that you need to build a microservice. Your team can use these services to decouple and fragment your environment to the level of granularity desired.

Can Lambda run jar file?

Lambda supports two types of deployment packages: container images and . zip file archives. This page describes how to create your deployment package as a . zip file or Jar file, and then use the deployment package to deploy your function code to AWS Lambda using the AWS Command Line Interface (AWS CLI).


1 Answers

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

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

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

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

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.

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

like image 179
Stefan Isele - prefabware.com Avatar answered Oct 04 '22 19:10

Stefan Isele - prefabware.com