File tree 2 files changed +13
-13
lines changed
examples/powertools-examples-core/sam 2 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 35
35
import java .io .PrintWriter ;
36
36
import java .nio .charset .Charset ;
37
37
38
+ import com .amazonaws .services .lambda .runtime .events .APIGatewayProxyResponseEvent ;
39
+ import software .amazon .lambda .powertools .tracing .TracingUtils ;
40
+
38
41
public class AppStream implements RequestStreamHandler {
39
42
private static final ObjectMapper mapper = new ObjectMapper ();
40
43
private final static Logger log = LogManager .getLogger (AppStream .class );
@@ -45,17 +48,15 @@ public class AppStream implements RequestStreamHandler {
45
48
public void handleRequest (InputStream input , OutputStream output , Context context ) throws IOException {
46
49
BufferedReader reader = new BufferedReader (new InputStreamReader (input , Charset .forName ("US-ASCII" )));
47
50
PrintWriter writer = new PrintWriter (new BufferedWriter (new OutputStreamWriter (output , Charset .forName ("US-ASCII" ))));
48
- int nextChar ;
49
51
try {
50
- while ((nextChar = reader .read ()) != -1 ) {
51
- output .write (nextChar );
52
- }
52
+ APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent ()
53
+ .withStatusCode (200 )
54
+ .withBody ("output_body" );
55
+ output .write (response .toString ().getBytes ());
53
56
} catch (IOException e ) {
54
57
log .error ("Something has gone wrong: " , e );
55
58
} finally {
56
59
reader .close ();
57
- String finalString = writer .toString ();
58
- log .info ("Final string result: " + finalString );
59
60
writer .close ();
60
61
}
61
62
}
Original file line number Diff line number Diff line change @@ -44,13 +44,12 @@ Resources:
44
44
Environment :
45
45
Variables :
46
46
POWERTOOLS_LOGGER_SAMPLE_RATE : 0.7
47
-
48
- HelloWorldStreamFunctionUrl :
49
- Type : AWS::Lambda::Url
50
- Properties :
51
- TargetFunctionArn : !Ref HelloWorldStreamFunction
52
- AuthType : AWS_IAM
53
- InvokeMode : RESPONSE_STREAM
47
+ Events :
48
+ HelloWorld :
49
+ Type : Api
50
+ Properties :
51
+ Path : /hellostream
52
+ Method : get
54
53
55
54
Outputs :
56
55
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
You can’t perform that action at this time.
0 commit comments