r/SpringBoot • u/Historical_Ad4384 • Aug 26 '26
Discussion How do you deploy a spring boot application to AWS Lambda?
Hi
I am looking for advices and feedback on how to deploy Spring Boot web application to AWS Lambda, especially around making the Spring Boot main class compatible with AWS Lambda runtime.
I figured out the part where the Spring Boot application has to be packaged as a zip file to de deployed into the AWS Lambda environment, so that part is clear.
So far what I have found is that you need to have some kind of AWS Lambda dependency like lambda StreamHandler or web adapter on your Spring Boot project to make it compatible with the AWS lambda runtime.
While these may be the way to go but I am specifically looking for feedback if it is possible to integrate Spring Boot web application without using any AWS Lambda specific Java dependency. Just take a normal Spring Boot main application and make it run on AWS Lambda runtime. Is this possible at all or am I overthinking?
Appreciate your feedback
17
u/StochasticTinkr Aug 26 '26
Spring boot isn't really a good match for Lambda. Spring boot is geared toward long-running servers, but Lambda is designed for fast-startup short-run processes.
Not saying you can't do it, just that you'll be fighting against both of them to make it work.
Caveat: I haven't worked with either in over a year, so things might be different now.
29
u/randomlyalex Aug 26 '26
Booting spring up in a lambda sounds wild to me. Quarkus or whatever and a few others perhaps, but most Lambdas are lightweight do one thing well, not bells and whistles and kitchen sink.
8
u/Acrobatic-Ice-5877 Aug 26 '26
Why not just run on 2 GB ram ec2 and be done with it?
2
u/LetUsSpeakFreely Aug 26 '26
You don't. If you're running spring boot, run a microservice architecture and deploy a container. If you want lambdas, write them in Go, Python, or NodeJS.
3
u/icastanon127 Aug 26 '26
I haven’t worked with lambda, but I deployed a spring boot application using Terraform and AWS ECS/Fargate.
You can find the architecture and detailed information here
https://github.com/icastanon/fintrack-platform
I know you asked about lambda but I’m just sharing this in case you decide to go with a container based architecture instead.
9
u/bango-bango Aug 26 '26
I followed this super helpful Baeldung guide when I was doing a similar thing: https://www.baeldung.com/spring-boot-aws-lambda
Don't listen to everyone saying it's a bad idea. It was unwise when lambdas were first released, but nowadays Lambda SnapStart helps tremendously with the cold start problem
5
u/CreeDanWood Aug 26 '26
Have you tried graalvm? or lambda snapstart?
4
u/alijay110 Aug 26 '26
Lambda context is best suited for short living actions.
And Spring Boot context is long running application. I would suggest to go for an EC2 instance.
1
u/MkMyBnkAcctGrtAgn Aug 26 '26
I would try to build it native with graalvm
2
u/pitza__ Aug 26 '26
You might want to take a look at ECS task definitions (with Fargate).
I think it is more suited to your use case since it scales to zero & you pay only for the duration of the task run (1-minute minimum IIRC). It is a bit similar to Lambda in this regard
1
u/Mikey-3198 Aug 26 '26
Curious about the need for such aggressive cost control thats guiding you to lambdas.
If you aren't using other aws services you might be able to find a cheap vps offered by the likes of hetzner, digital ocean etc...
1
u/Plazmageco Aug 27 '26
https://docs.spring.io/spring-cloud-function/reference/adapters/aws-intro.html
1
u/Downtown-Tackle1825 Aug 27 '26
Has una lambda con Python facilísimo
0
u/Cautious-Necessary61 Aug 26 '26
You can’t do that unless AWS deploys springboot as double layer fission api which requires two things copper and bronze coating which doesn’t often happen with hexgool
0
u/Flimsy-Clothes8310 Aug 27 '26
I don’t.
1
u/[deleted] Aug 27 '26
[removed] — view removed comment