Spring Boot 3 application on AWS Lambda – Part 2 Introduction to AWS Serverless Java Container

Spring Boot 3 application on AWS Lambda – Part 2 Introduction to AWS Serverless Java Container

Introduction to AWS Serverless Java Container (for Spring Boot 3)

The AWS Serverless Java Container makes it easier to run Java applications written with frameworks such as Spring, Spring Boot 2 and 3, or JAX-RS/Jersey in Lambda. We have already seen that Micronaut framework also uses AWS Serverless Java Container.

The container provides adapter logic to minimize code changes. Incoming events are translated to the Servlet specification so that frameworks work as before **.

AWS Serverless Java Container delivers the core container and framework specific container like one for Spring Boot 3 which is the area of our interest for this article. There also other containers for Spring, Struts and Jersey frameworks. The major update to the version 2.0 has been recently released for all AWS Serverless Java Containers.

AWS Serverless Java Core Container provides also abstractions like AWSProxyRequest/Response for mapping of API Gateway (Rest) request to the Servlet model including different authorizers like the Amazon Cognito and HttpApiV2JwtAuthorizer.

Then everything will be proxied internally in the core container through the AwsHttpServletRequest/Response abstractions or their derivates like AwsProxyHttpServletRequest.

My personal wish is that a subset of abstractions i.e. from the com.amazonaws.serverless.proxy.model package like

-AwsProxyRequest
-ApiGatewayRequestIdentity
-AwsProxyRequestContext
-AwsProxyResponse

and others will be a part of a separate project and therefore also used without the usage of the all other AWS Serverless Java Container APIs only for purpose of mocking the API Gateway Request/Response (i.e. for Priming). I’ve already used them for Priming requests for Quarkus and Micronaut frameworks. Dependency to the AWS Serverless Java Container was included by default for the Micronaut on AWS Lambda SnapStart Priming example and needed to be added explicitly for the Quarkus on AWS Lambda SnapStart Priming example only to implement web request priming. We’ll make use of these abstractions in one of our subsequent articles when we’ll discuss cold and warm start time improvements for Spring Boot 3 application on AWS Lambda using AWS Lambda SnapStart in conjunction with priming techniques.

AWS Serverless Spring Boot 3 Container which internally uses AWS Serverless Java Core Container adds only several abstractions on top that like SpringBootLambdaContainerHandler abstraction (which inherits AwsLambdaServletContainerHandler from the core container) which can be created by giving SpringBoot class which is annotated with @SpringBootApplication as an input. For Spring Boot 3 applications that take longer than 10 seconds to start, there is an asyncronous way of creating SpringBootLambdaContainerHandler by using SpringBootProxyHandlerBuilder abstraction. Since version 2.0.0 it always runs asynchronously by default, in the prior versions we had to invoke asyncInit method (which is now became deprecated) to run the builder asynchronously. I’ll provide more detailed explanation about this with code examples in the next article of the series.

Conclusion

In this article we introduced AWS Serverless Java Container components like core and framework specific adaptors like for Spring Boot 3. In the next article of the series we’ll explore how to develop the Lambda functions using AWS Serverless Java Container (for Spring Boot) which receives the request from Amazon API Gateway and stores to and read from Amazon DynamoDB.

** Re-platforming Java applications using the updated AWS Serverless Java Container

Leave a Reply

Your email address will not be published. Required fields are marked *