Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
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

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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.

about 4 years ago · Santiago Trujillo Report

0

I came across this searching for an answer and agree that Spring is typically way too slow to startup for Lambda.

I think Spring Cloud has solved this problem now with Spring Cloud Function:

This project provides an adapter layer for a Spring Cloud Function application onto AWS Lambda. You can write an app with a single @Bean of type Function, Consumer or Supplier and it will be deployable in AWS

https://github.com/spring-cloud/spring-cloud-function

UPDATE: I've been working with Spring Cloud Function on AWS lambda a little more now. For most of my functions, the startup time is 4-5 seconds which isn't fantastic, but at the time of writing it is dirt cheap (free for the first millions requests/ $0.20 per million thereafter) and a strategy to prevent slow startups is to prevent the function(s) from ever shutting down (a.k.a. "Keeping them warm") by setting up a CloudWatch rule to constantly kickoff the function and keep it alive.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!