Write an AWS Lambda with Spring Cloud Function
We assume you have already created a Maven project following the instructions in Setup Maven project. The example below is intentionally minimal and demonstrates only the function signature and wiring.
package org.datapith.cdk4j.examples.springCloud;
import java.util.function.Function;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class Cdk4jSpringCloudApplication {
public static void main(String[] args) {
SpringApplication.run(Cdk4jSpringCloudApplication.class, args);
}
@Bean
public Function<String, String> uppercase() {
return String::toUpperCase;
}
}This is a standard Spring Boot application without AWS-specific implementation details. Apart from the Spring annotations (@Bean, @SpringBootApplication), the function contains no framework- or cloud-specific logic.
Spring Cloud Function enables writing Spring-based functions that are cloud-agnostic: the function logic is independent of how it is invoked and where it is deployed.
Adding the Maven dependency spring-cloud-function-adapter-aws allows the function to be packaged and executed as an AWS Lambda.