SlideShare a Scribd company logo
1 of 95
Download to read offline
Adopting Java for the
Serverless world
from the perspective of the AWS developer
Vadym Kazulkin, ip.labs, JUG Darmstadt , 19 Mai 2022
Contact
Vadym Kazulkin
ip.labs GmbH Bonn, Germany
Co-Organizer of the Java User Group Bonn
v.kazulkin@gmail.com
@VKazulkin
https://www.linkedin.com/in/vadymkazulkin
https://www.iplabs.de/
ip.labs
https://www.iplabs.de/
Java popularity
https://redmonk.com/rstephens/2021/08/05/top-20-june-2021/ Vadym Kazulkin @VKazulkin , ip.labs GmbH
AWS and Serverless
2020 Magic Quadrant for Cloud Infrastructure & Platform Services
https://pages.awscloud.com/GLOBAL-multi-DL-gartner-mq-cips-2020-learn.html?pg=LWIAWS
https://aws.amazon.com/de/resources/analyst-reports/gartner-mq-cips-2021/
Vadym Kazulkin @VKazulkin , ip.labs GmbH
The State of Serverless 2021
https://www.datadoghq.com/state-of-serverless/
Vadym Kazulkin @VKazulkin , ip.labs GmbH
The State of Serverless 2021
https://www.datadoghq.com/state-of-serverless/
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Life of the Java Serverless developer on
AWS
AWS Java Versions Support
• Java 8
• With extended long-term support
• Java 11 (since 2019)
• Only Long Term Support (LTS) by AWS
• Current LTS Java version is Java 17
• Amazon Corrett Support for 17 is released, but not currently available for
Lambda
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: https://aws.amazon.com/de/corretto/
Java ist very fast
and mature
programming
language…
Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea
… but Serverless
adoption of Java
looks like this
Vadym Kazulkin @VKazulkin , ip.labs GmbH
2020 AWS Lambda Benchmark Report for Developers, DevOps, and Decision Makers
https://newrelic.com/resources/ebooks/serverless-benchmark-report-aws-lambda-2020
Vadym Kazulkin @VKazulkin , ip.labs GmbH
The State of Serverless 2021
https://www.datadoghq.com/state-of-serverless/
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Developers love Java and will be happy
to use it for Serverless
But what are the challenges ?
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Serverless with Java challenges
• “cold start” times (latencies)
• memory footprint (high cost in AWS)
AWS Lambda Basics
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Creating AWS Lambda with Java 1/3
:
Source https://blog.runscope.com/posts/how-to-write-your-first-aws-lambda-function
Creating AWS Lambda with Java 2/3
:
Source https://blog.runscope.com/posts/how-to-write-your-first-aws-lambda-function
Creating AWS Lambda with Java 3/3
:
Source https://docs.aws.amazon.com/lambda/latest/dg/java-context.html
AWS Lambda Price Model
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Cost for Lambda
REQUEST DURATION
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Request Tier
$ 0.20
Per 1 Mio Requests
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Duration Tier
$ 0.00001667 (x86)
$ 0.00001333 (Arm)
Per GB-Second
Vadym Kazulkin @VKazulkin , ip.labs GmbH
GB-Second
ONE SECOND ONE GB
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Example
• 1 Mio requests
• Lambda x86 with 512MiB
• Each lambda takes 200ms
0.5 GiB * 0.2 sec * 1 Mio
= 100 000 GB-Seconds
Requests:
$0.20
GB-Seconds:
$1.67
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Challenge Number 1 with Java is a
big cold-start
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: https://www.serverless.com/blog/keep-your-lambdas-warm
Cold Start
:
Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go
Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
• Start Firecracker VM
• AWS Lambda starts the JVM
• Java runtime loads and initializes
handler class
• Static initializer block of the handler class is
executed
• Init-phase has full CPU access up to 10 seconds for
free for the managed execution environments
• Lambda calls the handler method
• Full CPU access only approx. at 1.8 GB “assigned”
memory to the function
Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go
Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
Michael Hart: „Shave 99.93% off your Lambda bill with this one weird trick“ https://hichaelmart.medium.com/shave-99-93-off-your-lambda-bill-with-this-one-weird-trick-33c0acebb2ea
Function lifecycle- a full cold start
Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go
Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
AWS Lambda cold start duration
per programming language
Source: Mikhail Shilkov: „AWS Lambda: Cold Start Duration per Language. 2020 edition” https://mikhail.io/serverless/coldstarts/aws/languages/
Cold start duration with Java
• Below 1 second is best-case cold start duration for very simple Lambda
like HelloWorld with no dependencies
• It goes up significantly with more complex scenarios
• Instantiation outside of the handler method (static initializer block) to
communicate with other (AWS) services (e.g. DynamoDB, SNS, SQS, 3rd party)
• Artifact size
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
AWS Lambda cold starts by memory size,
runtime and artifact size
Source: Mike Roberts "Analyzing Cold Start latency of AWS Lambda" https://blog.symphonia.io/posts/2020-06-30_analyzing_cold_start_latency_of_aws_lambda
Artifact Size:
• Small zip (1KB)
• Large zip (48MB)
• Large uberjar (53MB)
Cold start duration with Java
• Below 1 second is best-case cold start duration for very simple Lambda
like HelloWorld with no dependencies
• It goes up significantly with more complex scenarios
• Instantiation outside of the handler method (static instantiation) to communicate
with other (AWS) services (i.e. DynamoDB, SNS, SQS, 3rd party)
• Artifact size
• To minimize the cold start time apply best practices from this talk
• Worst-case cold starts can be higher than 10 and even 20 seconds
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
• Switch to the AWS SDK 2.0 for Java
• Lower footprint and more modular
• Allows to configure HTTP Client of your choice (i.e. Java own Basic HTTP Client or
newly introduced AWS Common Runtime async HTTP Client)
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Zoe Wang: „Introducing AWS Common Runtime HTTP Client in the AWS SDK for Java 2.x”
https://aws.amazon.com/de/blogs/developer/introducing-aws-common-runtime-http-client-in-the-aws-sdk-for-java-2-x/
S3AsyncClient.builder()
.httpClientBuilder(AwsCrtAsyncHttpClient.builder()
.maxConcurrency(50))
.build();
Best Practices and Recommendations
• Less (dependencies, classes) is more
• Include only required dependencies (e.g. not the whole AWS SDK 2.0 for Java, but the
dependencies to the clients to be used in Lambda)
• Exclude dependencies, which you don‘t need at runtime e.g. test frameworks like Junit
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>dynamodb</artifactId>
<version>2.10.86</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.10.86</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Best Practices and Recommendations
• Initialize dependencies during initialization phase
• Use static initialization in the handler class, instead of in the handler method (e.g.
handleRequest) to take the advantage of the access to the full CPU core for max 10 seconds
• In case of DynamoDB client put the following code outside of the handler method:
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()...build();
DynamoDB dynamoDB = new DynamoDB(client);
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
Best Practices and Recommendations
Provide all known values (for building clients i.e. DynamoDB client) to
avoid auto-discovery
• credential provider, region, endpoint
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
.withRegion(Regions.US_WEST_2)
.withCredentials(new ProfileCredentialsProvider("myProfile"))
.build();
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
Best Practices and Recommendations
Best Practices and Recommendations
• Prime dependencies during initialization phase
• „Fake“ the calls to pre-initalize „some other expensive stuff“
• In case of DynamoDB client put the following code outside of the handler method to pre-
initialize the Jackson Marshaller:
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()...build();
DynamoDB dynamoDB = new DynamoDB(client);
Table table = dynamoDB.getTable(„mytable");
Item item = table.getItem("Id", 210);
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
getItem() call forces Jackson Marshallers to initialize
Best Practices and Recommendations
Using Tiered Compilation
• Achieve up to 60% faster startup times can use level 1 compilation with
little risk of reducing warm start performance
Mark Sailes: "Optimizing AWS Lambda function performance for Java”
https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-function-performance-for-java/
Avoid:
• reflection
• runtime byte code generation
• runtime generated proxies
• dynamic class loading
Use DI Frameworks which aren‘t reflection-based
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8
Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
Best Practices and Recommendations
Cost optimization techniques
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Best Practices and Recommendations
Cost for Lambda
REQUEST DURATION
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Cost scales
linearly with
memory
Vadym Kazulkin @VKazulkin , ip.labs GmbH
More memory = more expensive?
Kazulkin @VKazulkin , ip.labs GmbH
Lambda Power Tuning 1/2
• Executes different
settings in parallel
• Outputs the optimal
setting
Image: https://github.com/alexcasalboni/aws-lambda-power-tuning Vadym Kazulkin @VKazulkin , ip.labs GmbH
Lambda Power Tuning 2/2
• Executes different
settings in parallel
• Outputs the optimal
setting
Image: https://github.com/alexcasalboni/aws-lambda-power-tuning
Alex Casalboni: “Deep dive: finding the optimal resources allocation for your Lambda functions“
https://dev.to/aws/deep-dive-finding-the-optimal-resources-allocation-for-your-lambda-functions-35a6
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Optimizing AWS Lambda cost and
performance using AWS Compute
Optimizer
Source: Chad Schmutzer „Optimizing AWS Lambda cost and performance using AWS Compute Optimizer”
https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-cost-and-performance-using-aws-compute-optimizer/
Cost optimization
• Java is well optimized for long running server applications
• High startup times
• High memory utilization
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Even with all optimization applied we’ll be left with seconds of
the colds starts and high memory utilization
GraalVM enters the scene
Source: https://www.graalvm.org/
GraalVM
Goals:
Low footprint ahead-of-time mode for JVM-based languages
High performance for all languages
Convenient language interoperability and polyglot tooling
Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
Source: https://www.graalvm.org/22.1/docs/introduction/#available-distributions
GraalVM
Architecture
Sources: Practical Partial Evaluation for High-Performance Dynamic Language Runtimes http://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-truffle.pdf
„The LLVM Compiler Infrastructure“ https://llvm.org/
SubstrateVM
Source: Oleg Šelajev, Thomas Wuerthinger, Oracle: “Deep dive into using GraalVM for Java and JavaScript”
https://www.youtube.com/watch?v=a-XEZobXspo
GraalVM on SubstrateVM
A game changer for Java & Serverless?
Java Function compiled into a native executable using
GraalVM on SubstrateVM reduces
• “cold start” times
• memory footprint
by order of magnitude compared to running on JVM.
Current challenges with native
executable using GraalVM
• AWS doesn’t provide GraalVM (Native Image) as Java Runtime out
of the box
• AWS provides Custom Runtime Option
Custom Lambda Runtimes
GraalVM Complitation Modes
Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
AOT vs JIT
Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
GraalVM Native Cold Start 2021
Source: Aleksandr Filichkin: "AWS Lambda battle 2021: performance comparison for all languages (cold and warm start)“
https://filia-aleks.medium.com/aws-lambda-battle-2021-performance-comparison-for-all-languages-c1b441005fd1
Support of GraalVM native images in
Frameworks
Spring Boot/ Spring Framework : Ongoing work on experimental
Spring Native project.
Quarkus: a Kubernetes Native Java framework developed by Red
Hat tailored for GraalVM and HotSpot, crafted from best-of-breed
Java libraries and standards.
Micronaut: a modern, JVM-based, full-stack framework for building
modular, easily testable microservice and serverless applications.
Common principles for all frameworks
• Rely on as little reflection as possible
• Avoid runtime byte code generation, runtime generated proxies and
dynamic class loading as much as possible
• Process annotations at compile time
• The common goals:
• increase developer productivity
• Decrease cold start times compared to plain Java solution (with and without
the usage of Graal VM Native Image) using various optimization techniques
• Currently only available for Micronaut
Steps to deploy to AWS
• Installation prerequisites
• Framework of your choice (Micronaut, Quarkus, Spring Native)
• GraalVM and Native Image
• Apache Maven or Gradle
• AWS CLI and AWS SAM CLI (or SAM local for local testing)
• Build Linux executable of your application with GraalVM native-image
• Use Maven or Gradle plugin
• Deploy Linux executable as AWS Lambda Custom Runtime
• Function.zip with bootstrap Linux executable
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Quarkus
Source: https://quarkus.io/
Quarkus Example with Spring Annotations
Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/quarkus/pet-store
Build GraalVM Native Image with Quarkus
mvn –Pnative package
and optionally
-Dquarkus.native.container-
build=true
Build GraalVM Native Image with Quarkus
AWS Lambda Deployment of Custom
Runtime with SAM
Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/micronaut/pet-store
Local testing:
sam local start-api -t sam.native.yaml
curl localhost:3000/{yourURI}
Cloud deployment:
sam deploy -g -t sam.native.yaml
curl https://xxxxxxxxxx.execute-api.xx-xxxx-
1.amazonaws.com/Prod/pets/5
Quarkus Example with Quarkus Annotations
Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/quarkus/pet-store
src/main/resources/application.properties
Quarkus Additional Features
• AWS Lambda currently works by implementing and
com.amazonaws.services.lambda.runtime.RequestHandler interface or by using
Spring Web annotations model like @RestController, @RequestMapping
• Doesn‘t support Lambda function implementing Java 8 Function Interface
• Website (https://code.quarkus.io/)
• CLI for creating the App
• quarkus create app
• use quarkus-amazon-lambda extension in pom.xml
• quarkus build --native -Dquarkus.native.container-build=true
• Eclipse MicroProfile compatible
• Funqy for multi cloud solutions
Quarkus-Fanqy AWS Serverless Support
• AWS Lambda
• AWS API Gateway
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: https://quarkus.io/guides/funqy-amazon-lambda-http
Micronaut Framework
Source: https://micronaut.io/
Micronaut Example
Build GraalVM Native Image with Quarkus
./mvnw package -Dpackaging=native-image
-Dmicronaut.runtime=lambda
Packaging can also have docker or
docker-native value
Micronaut Additional Features
• AWS Lambda currently works by implementing its own annotations
(very similar to Spring Web) and should potentially work with Spring Web
annotations model like @RestController, @RequestMapping
• Website (https://micronaut.io/launch) or CLI for creating the App
• Custom Validators
• No support for MicroProfile
• Micronaut AOT
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Micronaut® AOT: build-time optimizations
for Micronaut applications
Micronaut AOT is an extension to the Micronaut Framework which is the
foundation to many optimizations that can be implemented at build time
but weren’t possible solely with annotation processing.
By effectively analyzing the deployment environment, AOT is capable of
reducing startup times or distribution size for both native and JVM
deliverables.
Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications”
https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5
https://micronaut-projects.github.io/micronaut-maven-plugin/latest/examples/aot.html
./mvnw package -Dpackaging=native-image
-Dmicronaut.runtime=lambda -Dmicronaut.aot.enabled=true
Packaging can also have docker or
docker-native value
Micronaut® AOT: build-time optimizations
for Micronaut applications
Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications”
https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5
Micronaut® AOT: build-time optimizations
for Micronaut applications
Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications”
https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5
Spring (Boot) Framework
Source: https://spring.io/
Spring GraalVM Native Project
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: https://github.com/spring-projects-experimental/spring-native
Spring Native Example
Source: https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-function-aws
curl https://xxxxxxxxxx.execute-api.
xx-xxxx-1.amazonaws.com/prod/book/5
Build GraalVM Native Image with Spring
mvn –Pnative package
Source: https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-function-aws
Spring Native
• AWS Lambda currently only works by implementing Java 8 Functional Interface
• Doesn‘t support Lambda function implementing
com.amazonaws.services.lambda.runtime.RequestHandler interface
• Doesn‘t support Spring Web Annotations model like @RestController,
@RequestMapping, which Quarkus and Micronaut do
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Framework Comparison
• Project Initializer
• Programming Model
• Database Access Model Support
• Testing Support
• Standards Support (i.e. MicroProfile)
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: „Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! by Michel Schudel“
https://www.youtube.com/watch?v=hnEXOqcNXPs
„Micronaut 2.0 vs Quarkus 1.3.1 vs Spring Boot 2.3 Performance on JDK 14“ https://www.youtube.com/watch?v=rJFgdFIs_k8
„Java EE, Jakarta EE, MicroProfile, or Maybe All of Them” https://www.eclipse.org/community/eclipse_newsletter/2019/february/Jakarta_Micro_All.php
Plain Java + GraalVM vs Quarkus + GraalVM
Vadym Kazulkin @VKazulkin , ip.labs GmbH
https://filia-aleks.medium.com/aws-lambda-graalvm-native-quarkus-vs-plain-java-90176eff515d
Lambda demo with common Java
application frameworks
Vadym Kazulkin @VKazulkin , ip.labs GmbH
https://github.com/aws-samples/serverless-java-frameworks-samples
Lambda Container Image Support
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: „https://aws.amazon.com/de/blogs/aws/new-for-aws-lambda-container-image-support/
Lambda Container Image Support
• What about the support of the current Java version for
Lambda?
• Amazon Corretto provides Long Term Support (LTS)
• Currently only Java 8, Java 11
• Use Container (Docker) Image with i.e. Java 18
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Source: https://aws.amazon.com/de/corretto/
Lambda Container Image Support with Java 18
Vadym Kazulkin @VKazulkin , ip.labs GmbH
https://aws.amazon.com/de/blogs/compute/build-a-custom-java-runtime-for-aws-lambda//
Conclusion
• GraalVM and Frameworks are really powerful with a lot of potential
• GraalVM Native Image improves cold starts and memory footprint
significally
• GraalVM Native Image is currently not without challenges
• AWS Lambda Custom Runtime requires Linux executable only
• Building Custom Runtime requires some additional effort
• Build time is a factor
• You pay for the init-phase of the function packaged as AWS Lambda Custom Runtime
• Init-phase is free for the managed runtimes like Java 8 and Java 11 (Corretto)
Vadym Kazulkin @VKazulkin , ip.labs GmbH
Personal Recommendations (highly opinionated)
• By default start with plain managed Java Long Term Support Version with Amazon
Corretto 11 + optionally your favorite framework (Micronaut, Quarkus)
• If you don‘t want to miss years of innovation and use the newest Java Version?
• Use Lambda Docker (Container) Image Support
• If your function needs constantly low response times for the known period of time ?
• Use Provisioned Concurrency additionally
• If your function needs constantly low response time and low cost is a requirement?
• Use GraalVM Native Image + optionally your favorite framework (Micronaut, Quarkus, Spring
Boot Native) and AWS Lambda Custom Runtime
• The usage of the frameworks (Micronaut, Quarkus, Spring Boot GraalVM Native)
may improve your productivity but may add up additional costs (longer build time,
larger cold starts)
Try it yourselves
• Quarkus
• https://github.com/aws-samples/aws-quarkus-demo/tree/main/lambda
• https://quarkus.io/guides/amazon-lambda
• Micronaut
• https://github.com/micronaut-guides/micronaut-function-aws-lambda
• Spring Native
• https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-
function-aws
• Misc examples with all frameworks
• https://github.com/awslabs/aws-serverless-java-container/tree/master/samples
What about Project Helidon?
Source: https://helidon.io
www.iplabs.de
Accelerate Your Photo Business
Get in Touch

More Related Content

Similar to Adopting Java for the Serverless World at JUG Bonn 2022

Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Vadym Kazulkin
 
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and BostonAdopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and BostonVadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...Vadym Kazulkin
 
Adapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaAdapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaVadym Kazulkin
 
Adopting Java for the Serverless world at JUG Hamburg
Adopting Java for the Serverless world at  JUG HamburgAdopting Java for the Serverless world at  JUG Hamburg
Adopting Java for the Serverless world at JUG HamburgVadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...Vadym Kazulkin
 
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...Vadym Kazulkin
 
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...Vadym Kazulkin
 
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...Vadym Kazulkin
 
Serverless in Java Lessons learnt
Serverless in Java Lessons learntServerless in Java Lessons learnt
Serverless in Java Lessons learntKrzysztof Pawlowski
 
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...Amazon Web Services
 
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...Vadym Kazulkin
 
Serverless in java Lessons learnt
Serverless in java Lessons learntServerless in java Lessons learnt
Serverless in java Lessons learntKrzysztof Pawlowski
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudAmazon Web Services
 
Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB AtlasWebinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB AtlasMongoDB
 
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...Amazon Web Services
 
Building Serverless APIs (January 2017)
Building Serverless APIs (January 2017)Building Serverless APIs (January 2017)
Building Serverless APIs (January 2017)Julien SIMON
 
FaaS or not to FaaS ServerlessDays Tel Aviv 2019
FaaS or not to FaaS ServerlessDays Tel Aviv 2019FaaS or not to FaaS ServerlessDays Tel Aviv 2019
FaaS or not to FaaS ServerlessDays Tel Aviv 2019Vadym Kazulkin
 
Kotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambdaKotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambdaBert Añasco
 
Riga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaRiga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaAntons Kranga
 

Similar to Adopting Java for the Serverless World at JUG Bonn 2022 (20)

Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
Adopting Java for the Serverless World at Voxxed Days Bruxelles 2023
 
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and BostonAdopting Java for the Serverless world at Serverless Meetup New York and Boston
Adopting Java for the Serverless world at Serverless Meetup New York and Boston
 
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...How to reduce cold starts for Java Serverless applications in AWS at Serverle...
How to reduce cold starts for Java Serverless applications in AWS at Serverle...
 
Adapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG BarcelonaAdapting Java for the Serverless World at JUG Barcelona
Adapting Java for the Serverless World at JUG Barcelona
 
Adopting Java for the Serverless world at JUG Hamburg
Adopting Java for the Serverless world at  JUG HamburgAdopting Java for the Serverless world at  JUG Hamburg
Adopting Java for the Serverless world at JUG Hamburg
 
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
How to reduce cold starts for Java Serverless applications in AWS at InfoShar...
 
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
 
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
 
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
AWS Lambda SnapStart: Why, How and What AWS Serverless Meetup New York Boston...
 
Serverless in Java Lessons learnt
Serverless in Java Lessons learntServerless in Java Lessons learnt
Serverless in Java Lessons learnt
 
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...
Customer Case Study: Land Registry as a Service in the Cloud - AWS PS Summit ...
 
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
FaaS or not to FaaS. Visible and invisible benefits of the Serverless paradig...
 
Serverless in java Lessons learnt
Serverless in java Lessons learntServerless in java Lessons learnt
Serverless in java Lessons learnt
 
Getting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless CloudGetting Started with AWS Lambda and the Serverless Cloud
Getting Started with AWS Lambda and the Serverless Cloud
 
Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB AtlasWebinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
Webinar: Serverless Architectures with AWS Lambda and MongoDB Atlas
 
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...
AWS re:Invent 2016: Monitoring, Hold the Infrastructure: Getting the Most fro...
 
Building Serverless APIs (January 2017)
Building Serverless APIs (January 2017)Building Serverless APIs (January 2017)
Building Serverless APIs (January 2017)
 
FaaS or not to FaaS ServerlessDays Tel Aviv 2019
FaaS or not to FaaS ServerlessDays Tel Aviv 2019FaaS or not to FaaS ServerlessDays Tel Aviv 2019
FaaS or not to FaaS ServerlessDays Tel Aviv 2019
 
Kotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambdaKotlin for backend using serverless + aws lambda
Kotlin for backend using serverless + aws lambda
 
Riga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS LambdaRiga DevDays 2017 - Efficient AWS Lambda
Riga DevDays 2017 - Efficient AWS Lambda
 

More from Vadym Kazulkin

Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Vadym Kazulkin
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Vadym Kazulkin
 
Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Vadym Kazulkin
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Vadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Vadym Kazulkin
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...Vadym Kazulkin
 
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Vadym Kazulkin
 
Projects Valhalla and Loom DWX 2022
Projects Valhalla and Loom DWX 2022Projects Valhalla and Loom DWX 2022
Projects Valhalla and Loom DWX 2022Vadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Vadym Kazulkin
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Vadym Kazulkin
 
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Vadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Vadym Kazulkin
 
Writing less code with Serverless on AWS at OOP 2022
Writing less code with Serverless on AWS at OOP 2022Writing less code with Serverless on AWS at OOP 2022
Writing less code with Serverless on AWS at OOP 2022Vadym Kazulkin
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Vadym Kazulkin
 
Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021Vadym Kazulkin
 
Writing less code with Serverless on AWS at AWS User Group Nairobi
Writing less code with Serverless on AWS at AWS User Group NairobiWriting less code with Serverless on AWS at AWS User Group Nairobi
Writing less code with Serverless on AWS at AWS User Group NairobiVadym Kazulkin
 
Writing less code with Serverless on AWS at AWS Community Day DACH 2021
Writing less code with Serverless on AWS at AWS Community Day DACH 2021Writing less code with Serverless on AWS at AWS Community Day DACH 2021
Writing less code with Serverless on AWS at AWS Community Day DACH 2021Vadym Kazulkin
 
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...Vadym Kazulkin
 
Writing less code with Serverless on AWS at FrOSCon 2021
Writing less code with Serverless on AWS at FrOSCon 2021Writing less code with Serverless on AWS at FrOSCon 2021
Writing less code with Serverless on AWS at FrOSCon 2021Vadym Kazulkin
 

More from Vadym Kazulkin (20)

Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
Revolutionize DevOps lifecycle with Amazon CodeCatalyst and DevOps Guru at De...
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
Amazon DevOps Guru for the Serverless Applications at AWS Community Day NL 2023
 
Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...Making sense of service quotas of AWS Serverless services and how to deal wit...
Making sense of service quotas of AWS Serverless services and how to deal wit...
 
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
Github Copilot vs Amazon CodeWhisperer for Java developers at JCON 2023
 
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
Revolutionize DevOps with ML capabilities. Deep dive into Amazon CodeGuru and...
 
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...Amazon DevOps Guru for the Serverless Applications at  AWS Community Day Bene...
Amazon DevOps Guru for the Serverless Applications at AWS Community Day Bene...
 
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
Amazon CodeGuru vs SonarQube for Java Developers at JCon 2022
 
Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022Adopting Java for the Serverless World at JUG Saxony Day 2022
Adopting Java for the Serverless World at JUG Saxony Day 2022
 
Projects Valhalla and Loom DWX 2022
Projects Valhalla and Loom DWX 2022Projects Valhalla and Loom DWX 2022
Projects Valhalla and Loom DWX 2022
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
 
Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022Adopting Java for the Serverless World at JUG Darmstadt 2022
Adopting Java for the Serverless World at JUG Darmstadt 2022
 
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
Amazon CodeGuru vs SonarQube for Java Developers at AWS DeveloperWeek Europe ...
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
 
Writing less code with Serverless on AWS at OOP 2022
Writing less code with Serverless on AWS at OOP 2022Writing less code with Serverless on AWS at OOP 2022
Writing less code with Serverless on AWS at OOP 2022
 
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
Revolutionize DevOps with ML capabilities. Introduction to Amazon CodeGuru an...
 
Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021Projects Valhalla and Loom at IT Tage 2021
Projects Valhalla and Loom at IT Tage 2021
 
Writing less code with Serverless on AWS at AWS User Group Nairobi
Writing less code with Serverless on AWS at AWS User Group NairobiWriting less code with Serverless on AWS at AWS User Group Nairobi
Writing less code with Serverless on AWS at AWS User Group Nairobi
 
Writing less code with Serverless on AWS at AWS Community Day DACH 2021
Writing less code with Serverless on AWS at AWS Community Day DACH 2021Writing less code with Serverless on AWS at AWS Community Day DACH 2021
Writing less code with Serverless on AWS at AWS Community Day DACH 2021
 
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
Measure and Increase Developer Productivity with Help of Serverless at JCON 2...
 
Writing less code with Serverless on AWS at FrOSCon 2021
Writing less code with Serverless on AWS at FrOSCon 2021Writing less code with Serverless on AWS at FrOSCon 2021
Writing less code with Serverless on AWS at FrOSCon 2021
 

Recently uploaded

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 

Adopting Java for the Serverless World at JUG Bonn 2022

  • 1. Adopting Java for the Serverless world from the perspective of the AWS developer Vadym Kazulkin, ip.labs, JUG Darmstadt , 19 Mai 2022
  • 2. Contact Vadym Kazulkin ip.labs GmbH Bonn, Germany Co-Organizer of the Java User Group Bonn v.kazulkin@gmail.com @VKazulkin https://www.linkedin.com/in/vadymkazulkin https://www.iplabs.de/
  • 7. 2020 Magic Quadrant for Cloud Infrastructure & Platform Services https://pages.awscloud.com/GLOBAL-multi-DL-gartner-mq-cips-2020-learn.html?pg=LWIAWS https://aws.amazon.com/de/resources/analyst-reports/gartner-mq-cips-2021/ Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 8. The State of Serverless 2021 https://www.datadoghq.com/state-of-serverless/ Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 9. The State of Serverless 2021 https://www.datadoghq.com/state-of-serverless/ Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 10. Life of the Java Serverless developer on AWS
  • 11. AWS Java Versions Support • Java 8 • With extended long-term support • Java 11 (since 2019) • Only Long Term Support (LTS) by AWS • Current LTS Java version is Java 17 • Amazon Corrett Support for 17 is released, but not currently available for Lambda Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: https://aws.amazon.com/de/corretto/
  • 12. Java ist very fast and mature programming language… Image: burst.shopify.com/photos/a-look-across-the-landscape-with-view-of-the-sea … but Serverless adoption of Java looks like this Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 13. 2020 AWS Lambda Benchmark Report for Developers, DevOps, and Decision Makers https://newrelic.com/resources/ebooks/serverless-benchmark-report-aws-lambda-2020 Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 14. The State of Serverless 2021 https://www.datadoghq.com/state-of-serverless/ Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 15. Developers love Java and will be happy to use it for Serverless But what are the challenges ? Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 16. Serverless with Java challenges • “cold start” times (latencies) • memory footprint (high cost in AWS)
  • 17. AWS Lambda Basics Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 18. Creating AWS Lambda with Java 1/3 : Source https://blog.runscope.com/posts/how-to-write-your-first-aws-lambda-function
  • 19. Creating AWS Lambda with Java 2/3 : Source https://blog.runscope.com/posts/how-to-write-your-first-aws-lambda-function
  • 20. Creating AWS Lambda with Java 3/3 : Source https://docs.aws.amazon.com/lambda/latest/dg/java-context.html
  • 21. AWS Lambda Price Model Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 22. Cost for Lambda REQUEST DURATION Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 23. Request Tier $ 0.20 Per 1 Mio Requests Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 24. Duration Tier $ 0.00001667 (x86) $ 0.00001333 (Arm) Per GB-Second Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 25. GB-Second ONE SECOND ONE GB Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 26. Example • 1 Mio requests • Lambda x86 with 512MiB • Each lambda takes 200ms 0.5 GiB * 0.2 sec * 1 Mio = 100 000 GB-Seconds Requests: $0.20 GB-Seconds: $1.67 Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 27. Challenge Number 1 with Java is a big cold-start Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: https://www.serverless.com/blog/keep-your-lambdas-warm
  • 28. Cold Start : Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
  • 29. • Start Firecracker VM • AWS Lambda starts the JVM • Java runtime loads and initializes handler class • Static initializer block of the handler class is executed • Init-phase has full CPU access up to 10 seconds for free for the managed execution environments • Lambda calls the handler method • Full CPU access only approx. at 1.8 GB “assigned” memory to the function Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications Michael Hart: „Shave 99.93% off your Lambda bill with this one weird trick“ https://hichaelmart.medium.com/shave-99-93-off-your-lambda-bill-with-this-one-weird-trick-33c0acebb2ea
  • 30. Function lifecycle- a full cold start Sources: Ajay Nair „Become a Serverless Black Belt” https://www.youtube.com/watch?v=oQFORsso2go Tomasz Łakomy "Notes from Optimizing Lambda Performance for Your Serverless Applications“ https://tlakomy.com/optimizing-lambda-performance-for-serverless-applications
  • 31. AWS Lambda cold start duration per programming language Source: Mikhail Shilkov: „AWS Lambda: Cold Start Duration per Language. 2020 edition” https://mikhail.io/serverless/coldstarts/aws/languages/
  • 32. Cold start duration with Java • Below 1 second is best-case cold start duration for very simple Lambda like HelloWorld with no dependencies • It goes up significantly with more complex scenarios • Instantiation outside of the handler method (static initializer block) to communicate with other (AWS) services (e.g. DynamoDB, SNS, SQS, 3rd party) • Artifact size Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
  • 33. AWS Lambda cold starts by memory size, runtime and artifact size Source: Mike Roberts "Analyzing Cold Start latency of AWS Lambda" https://blog.symphonia.io/posts/2020-06-30_analyzing_cold_start_latency_of_aws_lambda Artifact Size: • Small zip (1KB) • Large zip (48MB) • Large uberjar (53MB)
  • 34. Cold start duration with Java • Below 1 second is best-case cold start duration for very simple Lambda like HelloWorld with no dependencies • It goes up significantly with more complex scenarios • Instantiation outside of the handler method (static instantiation) to communicate with other (AWS) services (i.e. DynamoDB, SNS, SQS, 3rd party) • Artifact size • To minimize the cold start time apply best practices from this talk • Worst-case cold starts can be higher than 10 and even 20 seconds Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/
  • 35. • Switch to the AWS SDK 2.0 for Java • Lower footprint and more modular • Allows to configure HTTP Client of your choice (i.e. Java own Basic HTTP Client or newly introduced AWS Common Runtime async HTTP Client) Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Zoe Wang: „Introducing AWS Common Runtime HTTP Client in the AWS SDK for Java 2.x” https://aws.amazon.com/de/blogs/developer/introducing-aws-common-runtime-http-client-in-the-aws-sdk-for-java-2-x/ S3AsyncClient.builder() .httpClientBuilder(AwsCrtAsyncHttpClient.builder() .maxConcurrency(50)) .build(); Best Practices and Recommendations
  • 36. • Less (dependencies, classes) is more • Include only required dependencies (e.g. not the whole AWS SDK 2.0 for Java, but the dependencies to the clients to be used in Lambda) • Exclude dependencies, which you don‘t need at runtime e.g. test frameworks like Junit Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/ https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2 <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.4.2</version> <scope>test</scope> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>dynamodb</artifactId> <version>2.10.86</version> </dependency> <dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bom</artifactId> <version>2.10.86</version> <type>pom</type> <scope>import</scope> </dependency> Best Practices and Recommendations
  • 37. • Initialize dependencies during initialization phase • Use static initialization in the handler class, instead of in the handler method (e.g. handleRequest) to take the advantage of the access to the full CPU core for max 10 seconds • In case of DynamoDB client put the following code outside of the handler method: AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()...build(); DynamoDB dynamoDB = new DynamoDB(client); Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/ Best Practices and Recommendations
  • 38. Provide all known values (for building clients i.e. DynamoDB client) to avoid auto-discovery • credential provider, region, endpoint AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard() .withRegion(Regions.US_WEST_2) .withCredentials(new ProfileCredentialsProvider("myProfile")) .build(); Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/ Best Practices and Recommendations
  • 39. Best Practices and Recommendations • Prime dependencies during initialization phase • „Fake“ the calls to pre-initalize „some other expensive stuff“ • In case of DynamoDB client put the following code outside of the handler method to pre- initialize the Jackson Marshaller: AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()...build(); DynamoDB dynamoDB = new DynamoDB(client); Table table = dynamoDB.getTable(„mytable"); Item item = table.getItem("Id", 210); Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/ getItem() call forces Jackson Marshallers to initialize
  • 40. Best Practices and Recommendations Using Tiered Compilation • Achieve up to 60% faster startup times can use level 1 compilation with little risk of reducing warm start performance Mark Sailes: "Optimizing AWS Lambda function performance for Java” https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-function-performance-for-java/
  • 41. Avoid: • reflection • runtime byte code generation • runtime generated proxies • dynamic class loading Use DI Frameworks which aren‘t reflection-based Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: Stefano Buliani : "Best practices for AWS Lambda and Java„ https://www.youtube.com/watch?v=ddg1u5HLwg8 Sean O‘Toole „AWS Lambda Java Tutorial: Best Practices to Lower Cold Starts” https://www.capitalone.com/tech/cloud/aws-lambda-java-tutorial-reduce-cold-starts/ Best Practices and Recommendations
  • 42. Cost optimization techniques Vadym Kazulkin @VKazulkin , ip.labs GmbH Best Practices and Recommendations
  • 43. Cost for Lambda REQUEST DURATION Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 44. Cost scales linearly with memory Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 45. More memory = more expensive? Kazulkin @VKazulkin , ip.labs GmbH
  • 46. Lambda Power Tuning 1/2 • Executes different settings in parallel • Outputs the optimal setting Image: https://github.com/alexcasalboni/aws-lambda-power-tuning Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 47. Lambda Power Tuning 2/2 • Executes different settings in parallel • Outputs the optimal setting Image: https://github.com/alexcasalboni/aws-lambda-power-tuning Alex Casalboni: “Deep dive: finding the optimal resources allocation for your Lambda functions“ https://dev.to/aws/deep-dive-finding-the-optimal-resources-allocation-for-your-lambda-functions-35a6 Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 48. Optimizing AWS Lambda cost and performance using AWS Compute Optimizer Source: Chad Schmutzer „Optimizing AWS Lambda cost and performance using AWS Compute Optimizer” https://aws.amazon.com/de/blogs/compute/optimizing-aws-lambda-cost-and-performance-using-aws-compute-optimizer/
  • 49. Cost optimization • Java is well optimized for long running server applications • High startup times • High memory utilization Vadym Kazulkin @VKazulkin , ip.labs GmbH Even with all optimization applied we’ll be left with seconds of the colds starts and high memory utilization
  • 50. GraalVM enters the scene Source: https://www.graalvm.org/
  • 51. GraalVM Goals: Low footprint ahead-of-time mode for JVM-based languages High performance for all languages Convenient language interoperability and polyglot tooling Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
  • 53. GraalVM Architecture Sources: Practical Partial Evaluation for High-Performance Dynamic Language Runtimes http://chrisseaton.com/rubytruffle/pldi17-truffle/pldi17-truffle.pdf „The LLVM Compiler Infrastructure“ https://llvm.org/
  • 54. SubstrateVM Source: Oleg Šelajev, Thomas Wuerthinger, Oracle: “Deep dive into using GraalVM for Java and JavaScript” https://www.youtube.com/watch?v=a-XEZobXspo
  • 55. GraalVM on SubstrateVM A game changer for Java & Serverless? Java Function compiled into a native executable using GraalVM on SubstrateVM reduces • “cold start” times • memory footprint by order of magnitude compared to running on JVM.
  • 56. Current challenges with native executable using GraalVM • AWS doesn’t provide GraalVM (Native Image) as Java Runtime out of the box • AWS provides Custom Runtime Option
  • 58. GraalVM Complitation Modes Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
  • 59. AOT vs JIT Source: „Everything you need to know about GraalVM by Oleg Šelajev & Thomas Wuerthinger” https://www.youtube.com/watch?v=ANN9rxYo5Hg
  • 60. GraalVM Native Cold Start 2021 Source: Aleksandr Filichkin: "AWS Lambda battle 2021: performance comparison for all languages (cold and warm start)“ https://filia-aleks.medium.com/aws-lambda-battle-2021-performance-comparison-for-all-languages-c1b441005fd1
  • 61. Support of GraalVM native images in Frameworks Spring Boot/ Spring Framework : Ongoing work on experimental Spring Native project. Quarkus: a Kubernetes Native Java framework developed by Red Hat tailored for GraalVM and HotSpot, crafted from best-of-breed Java libraries and standards. Micronaut: a modern, JVM-based, full-stack framework for building modular, easily testable microservice and serverless applications.
  • 62. Common principles for all frameworks • Rely on as little reflection as possible • Avoid runtime byte code generation, runtime generated proxies and dynamic class loading as much as possible • Process annotations at compile time • The common goals: • increase developer productivity • Decrease cold start times compared to plain Java solution (with and without the usage of Graal VM Native Image) using various optimization techniques • Currently only available for Micronaut
  • 63. Steps to deploy to AWS • Installation prerequisites • Framework of your choice (Micronaut, Quarkus, Spring Native) • GraalVM and Native Image • Apache Maven or Gradle • AWS CLI and AWS SAM CLI (or SAM local for local testing) • Build Linux executable of your application with GraalVM native-image • Use Maven or Gradle plugin • Deploy Linux executable as AWS Lambda Custom Runtime • Function.zip with bootstrap Linux executable Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 65. Quarkus Example with Spring Annotations Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/quarkus/pet-store
  • 66. Build GraalVM Native Image with Quarkus mvn –Pnative package and optionally -Dquarkus.native.container- build=true
  • 67. Build GraalVM Native Image with Quarkus
  • 68. AWS Lambda Deployment of Custom Runtime with SAM Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/micronaut/pet-store Local testing: sam local start-api -t sam.native.yaml curl localhost:3000/{yourURI} Cloud deployment: sam deploy -g -t sam.native.yaml curl https://xxxxxxxxxx.execute-api.xx-xxxx- 1.amazonaws.com/Prod/pets/5
  • 69. Quarkus Example with Quarkus Annotations Source: https://github.com/awslabs/aws-serverless-java-container/tree/master/samples/quarkus/pet-store src/main/resources/application.properties
  • 70. Quarkus Additional Features • AWS Lambda currently works by implementing and com.amazonaws.services.lambda.runtime.RequestHandler interface or by using Spring Web annotations model like @RestController, @RequestMapping • Doesn‘t support Lambda function implementing Java 8 Function Interface • Website (https://code.quarkus.io/) • CLI for creating the App • quarkus create app • use quarkus-amazon-lambda extension in pom.xml • quarkus build --native -Dquarkus.native.container-build=true • Eclipse MicroProfile compatible • Funqy for multi cloud solutions
  • 71. Quarkus-Fanqy AWS Serverless Support • AWS Lambda • AWS API Gateway Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: https://quarkus.io/guides/funqy-amazon-lambda-http
  • 74. Build GraalVM Native Image with Quarkus ./mvnw package -Dpackaging=native-image -Dmicronaut.runtime=lambda Packaging can also have docker or docker-native value
  • 75. Micronaut Additional Features • AWS Lambda currently works by implementing its own annotations (very similar to Spring Web) and should potentially work with Spring Web annotations model like @RestController, @RequestMapping • Website (https://micronaut.io/launch) or CLI for creating the App • Custom Validators • No support for MicroProfile • Micronaut AOT Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 76. Micronaut® AOT: build-time optimizations for Micronaut applications Micronaut AOT is an extension to the Micronaut Framework which is the foundation to many optimizations that can be implemented at build time but weren’t possible solely with annotation processing. By effectively analyzing the deployment environment, AOT is capable of reducing startup times or distribution size for both native and JVM deliverables. Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications” https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5 https://micronaut-projects.github.io/micronaut-maven-plugin/latest/examples/aot.html ./mvnw package -Dpackaging=native-image -Dmicronaut.runtime=lambda -Dmicronaut.aot.enabled=true Packaging can also have docker or docker-native value
  • 77. Micronaut® AOT: build-time optimizations for Micronaut applications Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications” https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5
  • 78. Micronaut® AOT: build-time optimizations for Micronaut applications Source: “Introducing Micronaut® AOT: build-time optimizations for your Micronaut applications” https://medium.com/graalvm/introducing-micronaut-aot-build-time-optimizations-for-your-micronaut-applications-68b8f1302c5
  • 79. Spring (Boot) Framework Source: https://spring.io/
  • 80. Spring GraalVM Native Project Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: https://github.com/spring-projects-experimental/spring-native
  • 81. Spring Native Example Source: https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-function-aws curl https://xxxxxxxxxx.execute-api. xx-xxxx-1.amazonaws.com/prod/book/5
  • 82. Build GraalVM Native Image with Spring mvn –Pnative package Source: https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud-function-aws
  • 83. Spring Native • AWS Lambda currently only works by implementing Java 8 Functional Interface • Doesn‘t support Lambda function implementing com.amazonaws.services.lambda.runtime.RequestHandler interface • Doesn‘t support Spring Web Annotations model like @RestController, @RequestMapping, which Quarkus and Micronaut do Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 84. Framework Comparison • Project Initializer • Programming Model • Database Access Model Support • Testing Support • Standards Support (i.e. MicroProfile) Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: „Battle Of The Microservice Frameworks: Micronaut versus Quarkus edition! by Michel Schudel“ https://www.youtube.com/watch?v=hnEXOqcNXPs „Micronaut 2.0 vs Quarkus 1.3.1 vs Spring Boot 2.3 Performance on JDK 14“ https://www.youtube.com/watch?v=rJFgdFIs_k8 „Java EE, Jakarta EE, MicroProfile, or Maybe All of Them” https://www.eclipse.org/community/eclipse_newsletter/2019/february/Jakarta_Micro_All.php
  • 85. Plain Java + GraalVM vs Quarkus + GraalVM Vadym Kazulkin @VKazulkin , ip.labs GmbH https://filia-aleks.medium.com/aws-lambda-graalvm-native-quarkus-vs-plain-java-90176eff515d
  • 86. Lambda demo with common Java application frameworks Vadym Kazulkin @VKazulkin , ip.labs GmbH https://github.com/aws-samples/serverless-java-frameworks-samples
  • 87. Lambda Container Image Support Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: „https://aws.amazon.com/de/blogs/aws/new-for-aws-lambda-container-image-support/
  • 88. Lambda Container Image Support • What about the support of the current Java version for Lambda? • Amazon Corretto provides Long Term Support (LTS) • Currently only Java 8, Java 11 • Use Container (Docker) Image with i.e. Java 18 Vadym Kazulkin @VKazulkin , ip.labs GmbH Source: https://aws.amazon.com/de/corretto/
  • 89. Lambda Container Image Support with Java 18 Vadym Kazulkin @VKazulkin , ip.labs GmbH https://aws.amazon.com/de/blogs/compute/build-a-custom-java-runtime-for-aws-lambda//
  • 90. Conclusion • GraalVM and Frameworks are really powerful with a lot of potential • GraalVM Native Image improves cold starts and memory footprint significally • GraalVM Native Image is currently not without challenges • AWS Lambda Custom Runtime requires Linux executable only • Building Custom Runtime requires some additional effort • Build time is a factor • You pay for the init-phase of the function packaged as AWS Lambda Custom Runtime • Init-phase is free for the managed runtimes like Java 8 and Java 11 (Corretto) Vadym Kazulkin @VKazulkin , ip.labs GmbH
  • 91. Personal Recommendations (highly opinionated) • By default start with plain managed Java Long Term Support Version with Amazon Corretto 11 + optionally your favorite framework (Micronaut, Quarkus) • If you don‘t want to miss years of innovation and use the newest Java Version? • Use Lambda Docker (Container) Image Support • If your function needs constantly low response times for the known period of time ? • Use Provisioned Concurrency additionally • If your function needs constantly low response time and low cost is a requirement? • Use GraalVM Native Image + optionally your favorite framework (Micronaut, Quarkus, Spring Boot Native) and AWS Lambda Custom Runtime • The usage of the frameworks (Micronaut, Quarkus, Spring Boot GraalVM Native) may improve your productivity but may add up additional costs (longer build time, larger cold starts)
  • 92. Try it yourselves • Quarkus • https://github.com/aws-samples/aws-quarkus-demo/tree/main/lambda • https://quarkus.io/guides/amazon-lambda • Micronaut • https://github.com/micronaut-guides/micronaut-function-aws-lambda • Spring Native • https://github.com/spring-projects-experimental/spring-native/tree/main/samples/cloud- function-aws • Misc examples with all frameworks • https://github.com/awslabs/aws-serverless-java-container/tree/master/samples
  • 93. What about Project Helidon? Source: https://helidon.io
  • 94.
  • 95. www.iplabs.de Accelerate Your Photo Business Get in Touch