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
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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With