Skip to content

Commit 6c1405c

Browse files
committed
feat(aws): add AWS Lambda stream handler for serverless deployment
1 parent bc66ad5 commit 6c1405c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.demo.handler;
2+
3+
import com.amazonaws.serverless.exceptions.ContainerInitializationException;
4+
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
5+
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
6+
import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
7+
import com.amazonaws.services.lambda.runtime.Context;
8+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
9+
import com.example.demo.DemoApplication;
10+
11+
import java.io.IOException;
12+
import java.io.InputStream;
13+
import java.io.OutputStream;
14+
15+
public class StreamLambdaHandler implements RequestStreamHandler {
16+
17+
private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
18+
19+
static {
20+
try {
21+
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(DemoApplication.class);
22+
} catch (ContainerInitializationException e) {
23+
// If we fail here, re-throw the exception to force another cold start
24+
e.printStackTrace();
25+
throw new RuntimeException("Could not initialize Spring Boot application", e);
26+
}
27+
}
28+
29+
@Override
30+
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
31+
throws IOException {
32+
handler.proxyStream(inputStream, outputStream, context);
33+
}
34+
}

0 commit comments

Comments
 (0)