Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit bb9395c

Browse files
chore: stream example for core util
1 parent 8b20cbb commit bb9395c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package helloworld;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.io.OutputStream;
6+
import java.util.Map;
7+
8+
import com.amazonaws.services.lambda.runtime.Context;
9+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
10+
import com.fasterxml.jackson.databind.ObjectMapper;
11+
import software.amazon.lambda.powertools.logging.Logging;
12+
import software.amazon.lambda.powertools.metrics.Metrics;
13+
14+
public class AppStream implements RequestStreamHandler {
15+
private static final ObjectMapper mapper = new ObjectMapper();
16+
17+
@Override
18+
@Logging(logEvent = true)
19+
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
20+
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
21+
Map map = mapper.readValue(input, Map.class);
22+
23+
System.out.println(map.size());
24+
}
25+
}

java/CoreUtilities/template.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ Resources:
3434
Path: /hello
3535
Method: get
3636

37+
HelloWorldStreamFunction:
38+
Type: AWS::Serverless::Function
39+
Properties:
40+
CodeUri: HelloWorldFunction
41+
Handler: helloworld.AppStream::handleRequest
42+
MemorySize: 512
43+
Tracing: Active
44+
Environment:
45+
Variables:
46+
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.7
47+
Events:
48+
HelloWorld:
49+
Type: Api
50+
Properties:
51+
Path: /hellostream
52+
Method: get
53+
3754
Outputs:
3855
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
3956
# Find out more about other implicit resources you can reference within SAM

0 commit comments

Comments
 (0)