Skip to content

Commit 87cca46

Browse files
committed
Update doc
1 parent 7a5e7c2 commit 87cca46

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

README.md

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,30 @@ including Java), visit https://maxday.github.io/lambda-perf/.
2828

2929
## Getting started
3030

31-
If you have never used AWS Lambda before, check out this getting started guide.
31+
If you have never used AWS Lambda before, check out this getting started guide.
3232

3333
To create a simple lambda function, follow the following steps:
34+
3435
1. Create Kotlin multiplatform project
3536
2. Include library dependency into your module-level build.gradle file
37+
3638
```kotlin
3739
//..
3840
kotlin {
3941
//..
4042
sourceSets {
4143
nativeMain.dependencies {
42-
implementation("io.github.trueangle:lambda-runtime:0.0.1")
43-
implementation("io.github.trueangle:lambda-events:0.0.1")
44+
implementation("io.github.trueangle:lambda-runtime:0.0.2")
45+
implementation("io.github.trueangle:lambda-events:0.0.2")
4446
}
4547
}
4648
//..
4749
}
4850
//..
4951
```
52+
5053
3. Specify application entry point reference and supported targets
54+
5155
```kotlin
5256
//..
5357
kotlin {
@@ -68,15 +72,20 @@ kotlin {
6872
}
6973
//..
7074
```
75+
7176
4. Choose lambda function type.
7277

7378
There are two types of lambda functions:
7479

75-
**Buffered** Lambda function collects all the data it needs to return as a response before sending it back. This is a default behavior of Lambda function. Response payload max size: 6 MB.
80+
**Buffered** Lambda function collects all the data it needs to return as a response before sending
81+
it back. This is a default behavior of Lambda function. Response payload max size: 6 MB.
7682

7783
```kotlin
7884
class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGatewayV2Response> {
79-
override suspend fun handleRequest(input: APIGatewayV2Request, context: Context): APIGatewayV2Response {
85+
override suspend fun handleRequest(
86+
input: APIGatewayV2Request,
87+
context: Context
88+
): APIGatewayV2Response {
8089
return APIGatewayV2Response(
8190
statusCode = 200,
8291
body = "Hello world",
@@ -88,23 +97,33 @@ class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGa
8897
}
8998
```
9099

91-
**Streaming** functions, on the other hand, process events in real-time as they arrive, without any
92-
intermediate buffering. This method is well-suited for use cases requiring immediate data
93-
processing, such as real-time analytics or event-driven architectures where low-latency responses
94-
are crucial. [More details here.](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html)
100+
**Streaming** functions, on the other hand, sends back data as soon as it's available, rather than
101+
waiting for all the data to be ready. It processes and returns the response in chunks, piece by
102+
piece, which can be useful when you want to start delivering results right away, especially for
103+
large or ongoing tasks. This allows for faster responses and can handle data as it comes
104+
in. [More details here.](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html).
105+
For example, `SampleStreamingHandler` reads a large json file and streams it by chunks.
95106

96107
```kotlin
97108
class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel> {
98-
override suspend fun handleRequest(input: ByteArray, output: ByteWriteChannel, context: Context) {
109+
override suspend fun handleRequest(
110+
input: ByteArray,
111+
output: ByteWriteChannel,
112+
context: Context
113+
) {
99114
ByteReadChannel(SystemFileSystem.source(Path("hello.json")).buffered()).copyTo(output)
100115
}
101116
}
102117
```
103118

104-
5. Specify application entry point using standard `main`. Call `LambdaRuntime.run` to execute Lambda by passing handler to it.
119+
5. Specify application entry point using standard `main`. Call `LambdaRuntime.run` to execute Lambda
120+
by passing handler to it.
121+
105122
```kotlin
106123
fun main() = LambdaRuntime.run { HelloWorldLambdaHandler() }
124+
```
107125

126+
```kotlin
108127
// or SampleStreamingHandler for streaming lambda
109128
fun main() = LambdaRuntime.run { SampleStreamingHandler() }
110129

@@ -169,4 +188,16 @@ Log.fatal(message: T?) // Messages about serious errors that cause the applicati
169188
1. The list of supported targets for Kotlin Native (
170189
2.0.20-RC2) https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.20-RC2/
171190
2. Opened
172-
issue: https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
191+
issue: https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
192+
- If you are running the project build on MacOs you might come across a set of errors connected with
193+
curl linking e.g. `ld.lld: error: undefined symbol: curl_global_init`. This means that your local
194+
machine [uses different curl version from what is requested by the runtime](https://youtrack.jetbrains.com/issue/KTOR-6361/Curl-Error-linking-curl-in-linkDebugExecutableLinuxX64-on-macOS).
195+
To solve that either
196+
use [Gihub Actions workflow](https://github.com/trueangle/kotlin-native-aws-lambda-runtime/actions/workflows/buildLinux86_64.yml)
197+
or local docker container with ubuntu 22 under the hood. Example:
198+
```bash
199+
200+
docker build -t sample .
201+
docker run --rm -v $(pwd):/sample -w /sample sample ./gradlew build
202+
203+
```

sample/build.gradle.kts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ kotlin {
1919

2020
sourceSets {
2121
nativeMain.dependencies {
22-
implementation(projects.lambdaRuntime)
23-
implementation(projects.lambdaEvents)
22+
/* implementation(projects.lambdaRuntime)
23+
implementation(projects.lambdaEvents)*/
2424
implementation(libs.kotlin.serialization.json)
25-
/*implementation("io.github.trueangle:lambda-runtime:0.0.1")
26-
implementation("io.github.trueangle:lambda-events:0.0.1")*/
25+
implementation("io.github.trueangle:lambda-runtime:0.0.2")
26+
implementation("io.github.trueangle:lambda-events:0.0.2")
2727
}
2828
}
2929
}

0 commit comments

Comments
 (0)