@@ -33,7 +33,8 @@ If you have never used AWS Lambda before, check out this getting started guide.
3333To create a simple lambda function, follow the following steps:
34341 . Create Kotlin multiplatform project
35352 . Include library dependency into your module-level build.gradle file
36- ```
36+ ``` kotlin
37+ // ..
3738kotlin {
3839 // ..
3940 sourceSets {
@@ -44,9 +45,11 @@ kotlin {
4445 }
4546 // ..
4647}
48+ // ..
4749```
48503 . Specify application entry point reference and supported targets
49- ```
51+ ``` kotlin
52+ // ..
5053kotlin {
5154 // ..
5255 listOf (
@@ -63,16 +66,16 @@ kotlin {
6366 }
6467 // ..
6568}
69+ // ..
6670```
67714 . Choose lambda function type.
6872
6973There are two types of lambda functions:
7074
71- ** Buffered **
72- Buffered functions process incoming events by first collecting them
75+ ** Buffered** functions process incoming events by first collecting them
7376into a buffer before execution. This is a default behavior.
7477
75- ```
78+ ``` kotlin
7679class HelloWorldLambdaHandler : LambdaBufferedHandler <APIGatewayV2Request , APIGatewayV2Response > {
7780 override suspend fun handleRequest (input : APIGatewayV2Request , context : Context ): APIGatewayV2Response {
7881 return APIGatewayV2Response (
@@ -86,13 +89,12 @@ class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGa
8689}
8790```
8891
89- ** Streaming **
90- Streaming functions, on the other hand, process events in real-time as they arrive, without any
92+ ** Streaming** functions, on the other hand, process events in real-time as they arrive, without any
9193intermediate buffering. This method is well-suited for use cases requiring immediate data
9294processing, such as real-time analytics or event-driven architectures where low-latency responses
9395are crucial.
9496
95- ```
97+ ``` kotlin
9698class SampleStreamingHandler : LambdaStreamHandler <ByteArray , ByteWriteChannel > {
9799 override suspend fun handleRequest (input : ByteArray , output : ByteWriteChannel , context : Context ) {
98100 ByteReadChannel (SystemFileSystem .source(Path (" hello.json" )).buffered()).copyTo(output)
@@ -101,7 +103,7 @@ class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel>
101103```
102104
1031055 . Specify application entry point using standard ` main ` and ` LambdaRuntime.run ` functions
104- ```
106+ ``` kotlin
105107fun main () = LambdaRuntime .run { HelloWorldLambdaHandler () } // or SampleStreamingHandler for streaming lambda
106108```
107109
0 commit comments