You can use the aws-serverless-java-container library to run a Spring Boot 2 application in AWS Lambda. You can use the library within your Lambda handler to load your Spring Boot application and proxy events to it.
In the repository we have included a sample Spring Boot application to get you started.
Serverless Java Container is tested against Spring Boot version 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x and 2.7.x.
As of version 1.4 of Serverless Java Container we also support WebFlux applications.
xxxxxxxxxx
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
// If you are using HTTP APIs with the version 2.0 of the proxy model, use the getHttpApiV2ProxyHandler
// method: handler = SpringBootLambdaContainerHandler.getHttpApiV2ProxyHandler(Application.class);
} catch (ContainerInitializationException e) {
// if we fail here. We re-throw the exception to force another cold start
e.printStackTrace();
throw new RuntimeException("Could not initialize Spring Boot application", e);
}
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}
https://github.com/awslabs/aws-serverless-java-container/wiki/Quick-start---Spring-Boot2