This example was originally created by AWS Labs. We here at Serverless Guru forked the project from AWS Labs to make a version of the Spring Boot pet store example using the Serverless Framework instead. As Serverless.com partners, Serverless Guru also published other serverless framework content.
Note: The only sample in the samples/
folder that has been converted from SAM
to the Serverless Framework, is the one in the samples/springboot
folder.
The aws-serverless-java-container
makes it easy to run Java applications written with frameworks such as Spring, Spring Boot, Apache Struts, Jersey, or Spark in AWS Lambda.
Serverless Java Container natively supports API Gateway's proxy integration models for requests and responses, you can create and inject custom models for methods that use custom mappings.
Follow the quick start guides in our wiki to integrate Serverless Java Container with your project:
- Spring quick start
- Spring Boot quick start
- Apache Struts quick start
- Jersey quick start
- Spark quick start
Below is the most basic AWS Lambda handler example that launches a Spring application. You can also take a look at the samples in this repository, our main wiki page includes a step-by-step guide on how to deploy the various sample applications using Maven and the Serverless Framework.
public class StreamLambdaHandler implements RequestStreamHandler {
private static SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
static {
try {
handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.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 framework", e);
}
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}