package com.lambdajavablockchain; import com.amazonaws.serverless.exceptions.ContainerInitializationException; import com.amazonaws.serverless.proxy.model.AwsProxyRequest; import com.amazonaws.serverless.proxy.model.AwsProxyResponse; import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestStreamHandler; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class StreamLambdaHandler implements RequestStreamHandler { private static SpringBootLambdaContainerHandler handler; static { try { handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class); // For applications that take longer than 10 seconds to start, use the async builder: // long startTime = Instant.now().toEpochMilli(); // handler = new SpringBootProxyHandlerBuilder() // .defaultProxy() // .asyncInit(startTime) // .springBootApplication(Application.class) // .buildAndInitialize(); } 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); } } /** * Main entry point of Lambda function */ @Override public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException { handler.proxyStream(inputStream, outputStream, context); } }