The AWS team has created a serverless wrapper that exposes request and response objects. This should allow you to do what you need.In their handler you implement a new interface and their underlying functionality returns the request and response to you as AwsProxyRequest and AwsProxyResponse which should be children of HttpServletRequest and HttpServletResponse.
Code
public class StreamLambdaHandler implements RequestStreamHandler {
private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
private Logger log = LoggerFactory.getLogger(StreamLambdaHandler.class);
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
if (handler == null) {
try {
handler = SpringLambdaContainerHandler.getAwsProxyHandler(PetStoreSpringAppConfig.class);
} catch (ContainerInitializationException e) {
log.error("Cannot initialize Spring container", e);
outputStream.close();
throw new RuntimeException(e);
}
}
AwsProxyRequest request = LambdaContainerHandler.getObjectMapper().readValue(inputStream, AwsProxyRequest.class);
AwsProxyResponse resp = handler.proxy(request, context);
LambdaContainerHandler.getObjectMapper().writeValue(outputStream, resp);
// just in case it wasn't closed by the mapper
outputStream.close();
}
}
Source -> https://github.com/awslabs/aws-serverless-java-container