Spring Boot 3 application on AWS Lambda - Part 8 Introduction to Spring Cloud Function

Vadym Kazulkin - Jun 24 - - Dev Community

During the parts 2, 3 and 4 we introduced the concept behind the AWS Serverless Java Container and especially its variant for the Spring Boot (3) application, learned how to develop, deploy, run and optimize Spring Boot 3 Application on AWS Lambda using AWS Serverless Java Container. In the parts 5, 6 and 7 we did the same but for AWS Lambda Web Adapter. In this part of the series we'll introduce another alternative, the framework called Spring Cloud Function, concepts behind it and especially its integration with AWS Lambda.

Spring Cloud Function

Spring Cloud Function is a project with the following high-level goals:

  • Promote the implementation of business logic via functions.
  • Decouple the development lifecycle of business logic from any specific runtime target so that the same code can run as a web endpoint, a stream processor, or a task. One of these specific runtime targets can be AWS Lambda which will be focus of this article.
  • Support a uniform programming model across serverless providers, as well as the ability to run standalone (locally or in a PaaS).
  • Enable Spring Boot features (auto-configuration, dependency injection, metrics) on serverless providers.
  • It abstracts away all of the transport details and infrastructure, allowing the developer to keep all the familiar tools and processes, and focus firmly on business logic.

A simple function application (in context of Spring) is an application that contains beans of type Supplier, Java 8 Function interface or Consumer.

Spring Cloud Function on AWS Lambda

With Spring Cloud Function on AWS Lambda, AWS adapter takes a Spring Cloud Function app and converts it to a form that can run in AWS Lambda. So, with AWS it means that a simple function bean should somehow be recognized and executed in AWS Lambda environment. Which very well fits into the AWS Lambda model with Amazon API Gateway in front which similar to the Java 8 function receives the (HTTP) request, executes some business logic and then sends the (HTTP) response to the caller.



@SpringBootApplication
public class FunctionConfiguration {

      public static void main(String[] args) {
            SpringApplication.run(FunctionConfiguration.class, args);
      }

      @Bean
      public Function<String, String> uppercase() {
            return value -> value.toUpperCase();
      }
}


Enter fullscreen mode Exit fullscreen mode

The diagram below describes the request flow in the typical web application on AWS. AWS Request Adapter converts the JSON coming from Lambda function to the HttpServletRequest which then invokes the Spring Dispatcher Servlet which then interacts with our Spring Boot application on API level without starting web server (i.e. Tomcat). Then response flows back and AWS Response Adapter converts HttpServletResponse to JSON which Lambda function sends back to API Gateway.

Image description

Conclusion

In this part of the series, we introduced Spring Cloud Function and especially its integration with AWS Lambda and concepts behind it. In next part we'll learn how to develop and deploy application using this framework.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .