0

I am building a web application in AWS using the serverless architecture.

The purpose of the application is to expose a public API to upload files from around the world.

I use AWS API-Gateway and Lambda to execute my code and S3 as storage.

I know that it is very much possible and well supported (even by 3rd parties like the Serverless framework) to use Java Spring framework to write the code that I deploy in my Lambda function.

However, is it really recommended? Spring applications usually take 30 seconds or more to load completely and Lambda should run Immediately.

How come this option is even supported by AWS (since it sounds like a very bad idea)?

Yoaz Menda
  • 1,555
  • 2
  • 21
  • 43
  • I hope you are aware that Spring framework is very broad term. If I remember correctly, Spring Boot to bring up as standalone is what most of the times people use while writing Lambda. Not the heavy Spring components. In other words, people who code Lambda using Spring use minimal version of Spring. – kosa Jun 14 '17 at 15:15

3 Answers3

1

Java is one of the supported programming languages of AWS Lambda. It is possible to run an application using Java, you just have to take the warmup time into consideration, if that fits your use-case - then use it. You could also use SNS and a hook to your lambda to keep it warm if you do not receive requests

Shimon Tolts
  • 1,602
  • 14
  • 15
  • I am not talking about java warm up which is not more than 1-2 seconds maybe. I'm talking about Spring application load time that can take up to 30 seconds to start up. I'm asking why would they support such an option when it seems like the worst choice (Maybe Im missing something and they configure it in a way that doesn't take that much time to load) – Yoaz Menda Jun 14 '17 at 13:48
  • If your Spring application context takes 30 seconds to load, I suspect you have fundamentally not understood the concept of microservices. – Trent Bartlem Jun 14 '17 at 22:44
  • 1
    Application initial loading time has almost nothing to do with micro services in this aspect. also I haven't mentioned micro services anywhere in the conversation. If you run a spring boot application, it usually takes several seconds to load .it's just a fact. it's not "my" spring application. Since it takes that long I was wondering why would someone encourage the use of such solution in an environment (Lambda) in which the most important thing is how fast you fire up and return a response – Yoaz Menda Jun 15 '17 at 08:04
0

Personally, I would AVOID using java runtime for AWS lambda as much as possible. I understand that it's very tempting to use java assuming that you are looking into migrating an existing implementation into microservices. But you are always going to pay the penalty of slow warm-up time compared to other runtimes. You may also miss out on Java compiler optimisations as the lambda may not be invoked enough number of times to trigger C1 and C2 compilations.

My preference would be only to use java for lambda if you are planning to write a lean implementation, means no spring, hibernate etc. etc.

Suken Shah
  • 1,622
  • 14
  • 20
0

Using Java with AWS lambdas is perfectly fine but Lambdas are functions not applications!

So you should avoid to use a framework like Spring because you don't need that.

The question is what do you want to achieve in your function and why do you need a framework to execute such small amount of code? What's your use case?

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82