Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
serverless-java-container
A Java wrapper to run Spring, Spring Boot, Jersey, and other apps inside AWS Lambda.
provided by us. This StreamLambdaHandler implements com.amazonaws.services.lambda.runtime.RequestStreamHandler interface. After this we instatiate SpringBootLambdaContainerHandler handler like this
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". To its features belong:
For this we use aws-serverless-java-container-springboot2 project dependency provided in pom.xml. aws-serverless-java-container-springboot2 project is maintained by AWS with the goal to proxy the AWS API Gateway requests between the generic Lambda handler and the appropriate method of the Spring Boot Controller.
It was probably not a very good idea to write Lambda using Java programming language and Spring Boot Framework. Despite the well-spread usage and knowledge of this framework, the fact that Spring (Boot) heavily uses reflection and takes time to start the embedded Web Application Server led to very big cold starts which we'll explore in the next section. But now with SnapStart on AWS and GraalVM Native Image Support we have two more options how to optimize those cold starts. So let's explore how to write Lambda function using the Spring Boot. The code of this sample application (the same as for the first 3 parts but rewritten to use Spring Boot) can be found here. It provides AWS API Gateway and 2 Lambda functions: "CreateProduct" and "GetProductById". The products are stored in the Amazon DynamoDB. We'll use AWS Serverless Application Model (AWS SAM) for the infrastructure as a code.
Related posts
- Spring Boot 3 application on AWS Lambda - Part 3 Develop application with AWS Serverless Java Container
- Spring Boot 3 application on AWS Lambda - Part 2 Introduction to AWS Serverless Java Container
- AI PR adds auto generated comments to whole Spring Boot Project
- AI commented the entire Spring Boot codebase
- Spring Boot 3 And Java 17 Migration Guide