Skip to content

Commit 19f50cc

Browse files
committed
Update README.md
1 parent 3b67e9a commit 19f50cc

File tree

2 files changed

+37
-59
lines changed

2 files changed

+37
-59
lines changed

.github/workflows/buildLinux_x86_64.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ jobs:
2525
- name: Upload artifacts
2626
uses: actions/upload-artifact@v4
2727
with:
28-
name: kotlin-native-build
29-
path: sample/build/bin/lambda/release
28+
path: sample/build/lambda/release/sample.zip

README.md

Lines changed: 36 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
# Kotlin Native Runtime for AWS Lambda
22
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.trueangle/lambda-runtime/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.trueangle/lambda-runtime/badge.svg)
33

4-
A runtime for executing AWS Lambda Functions powered by Kotlin Native, designed to mitigate known
5-
cold start issues associated with the JVM platform.
4+
A runtime for executing AWS Lambda Functions using Kotlin Native, designed to reduce cold start issues common with the JVM platform.
65

7-
Project structure:
6+
## Project Structure
87

9-
- `lambda-runtime` — is a library that provides a Lambda runtime.
10-
- `lambda-events` — is a library with strongly-typed Lambda event models, such
11-
as `APIGatewayRequest`, `DynamoDBEvent`, `S3Event`, `KafkaEvent`, `SQSEvent` and so on.
8+
- `lambda-runtime`: Library providing the Lambda runtime.
9+
- `lambda-events`: Library with strongly-typed Lambda event models like `APIGatewayRequest`, `DynamoDBEvent`, `S3Event`, `KafkaEvent`, `SQSEvent`, etc.
10+
- `sample`: Sample project demonstrating examples of lambda functions.
1211

13-
The runtime supports the
14-
following [OS-only runtime machines](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html):
12+
## Supported [OS-only runtime machines](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)
1513

1614
- Amazon Linux 2023 (provided.al2023) with x86_64 architecture
1715
- Amazon Linux 2 (provided.al2) with x86_64 architecture
1816

1917
## Performance
2018

21-
Performance benchmarks reveal that Kotlin Native's "Hello World" Lambda function, executed on Amazon
22-
Linux 2023 (x86_64) with 1024MB of memory, ranks among the top 5 fastest cold starts. Its
23-
performance is on par with Python and .NET implementations. For a comparison with other languages (including Java), visit https://maxday.github.io/lambda-perf/.
19+
Benchmarks show that Kotlin Native's "Hello World" Lambda function on Amazon Linux 2023 (x86_64) with 1024MB memory is among the top 5 fastest cold starts, comparable to Python and .NET. For more details, visit [lambda-perf](https://maxday.github.io/lambda-perf/).
2420

2521
![Kotlin Native AWS Lambda Runtime benchmarks](docs/performance_hello_world.png)
2622

2723
## Getting started
2824

29-
To create a simple lambda function, follow the following steps:
25+
### 1. Create a Kotlin Multiplatform Project
26+
See [Kotlin Native](https://kotlinlang.org/docs/native-overview.html) for more details.
3027

31-
1. Create Kotlin multiplatform project
32-
2. Include library dependency into your module-level build.gradle file
28+
### 2. Add Dependencies
3329

30+
Add the following to your `build.gradle` file:
3431
```kotlin
32+
plugins {
33+
id("io.github.trueangle.plugin.lambda") version "0.0.1"
34+
}
35+
3536
kotlin {
3637
sourceSets {
3738
nativeMain.dependencies {
@@ -42,29 +43,27 @@ kotlin {
4243
}
4344
```
4445

45-
3. Specify application entry point reference and supported targets
46+
### 3. Specify Entry Point and Targets
4647
```kotlin
4748
kotlin {
4849
listOf(
4950
macosArm64(),
5051
macosX64(),
51-
linuxArm64(),
5252
linuxX64(),
5353
).forEach {
5454
it.binaries {
5555
executable {
56-
entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main"
56+
entryPoint = "com.github.trueangle.knative.lambda.runtime.sample.main" // Change this to your entry point
5757
}
5858
}
5959
}
6060
}
6161
```
6262

63-
4. Choose lambda function type. There are two types of lambda functions:
63+
### 4. Choose Lambda Function Type
6464

65-
### Buffered
66-
Buffered Lambda function collects all the data it needs to return as a response before sending
67-
it back. This is a default behavior of Lambda function. Response payload max size: 6 MB.
65+
#### Buffered
66+
Buffered Lambda functions collect all data before sending a response. This is a default behavior of Lambda function. Response payload max size: 6 MB.
6867

6968
```kotlin
7069
class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGatewayV2Response> {
@@ -83,13 +82,8 @@ class HelloWorldLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGa
8382
}
8483
```
8584

86-
### Streaming
87-
Streaming function, on the other hand, sends back data as soon as it's available, rather than
88-
waiting for all the data to be ready. It processes and returns the response in chunks, piece by
89-
piece, which can be useful when you want to start delivering results right away, especially for
90-
large or ongoing tasks. This allows for faster responses and can handle data as it comes
91-
in. [More details here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html).
92-
For example, `SampleStreamingHandler` reads a large json file and streams it by chunks.
85+
#### Streaming
86+
A streaming function sends data as soon as it's available, instead of waiting for all the data. It processes and returns the response in chunks, which is useful for large or ongoing tasks. This allows for faster responses and can handle data as it comes in. [More details here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-response-streaming.html). For example, `SampleStreamingHandler` reads a large json file and streams it in chunks.
9387

9488
```kotlin
9589
class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel> {
@@ -102,10 +96,8 @@ class SampleStreamingHandler : LambdaStreamHandler<ByteArray, ByteWriteChannel>
10296
}
10397
}
10498
```
105-
106-
5. Specify application entry point using standard `main` function. Call `LambdaRuntime.run` to
107-
execute Lambda
108-
by passing handler to it.
99+
### 5. Specify Application entry point
100+
Using standard `main` function. Call `LambdaRuntime.run` to execute Lambda by passing handler to it.
109101

110102
```kotlin
111103
fun main() = LambdaRuntime.run { HelloWorldLambdaHandler() }
@@ -122,21 +114,18 @@ For more examples refer to project's sample.
122114

123115
## Testing Runtime locally
124116

125-
To run runtime
126-
locally [aws runtime emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) is
127-
used. Here's how to run project's sample:
117+
Use the [AWS runtime emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) to run the runtime locally.
128118

129-
1. `./gradlew build` to build lambda executable
130-
2. Modify runtime-emulator/Dockerfile to set proper path to the generated executable (.kexe) file,
131-
located in build/bin/linuxX64/releaseExecutable
119+
1. `./gradlew build` to build the Lambda executable.
120+
2. Modify `runtime-emulator/Dockerfile` to set the path to the generated executable (.kexe) file in `build/bin/linuxX64/releaseExecutable`.
132121
3. Run `docker build -t sample:latest .`
133122
4. Start server `docker run -p 9000:8080 sample:latest`
134-
5. Execute function
123+
5. Execute the function
135124
using `curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'`
136125

137126
## Build and deploy to AWS
138127

139-
1. Apply plugin `id("io.github.trueangle.plugin.lambda") version "0.0.1"`
128+
1. Apply the plugin `id("io.github.trueangle.plugin.lambda") version "0.0.1"`
140129
2. Execute `./gradlew buildLambdaRelease`. The command will output the path to the archive containing lambda executable (YOUR_MODULE_NAME.kexe) located in (YOUR_MODULE_NAME/build/bin/lambda/release/YOUR_MODULE_NAME.zip)
141130
3. Deploy .zip archive to AWS. If you have never used AWS Lambda
142131
before, [learn how to deploy Lambda function as zip archive manually](https://docs.aws.amazon.com/lambda/latest/dg/configuration-function-zip.html)
@@ -153,7 +142,7 @@ $ aws lambda create-function --function-name LAMBDA_FUNCTION_NAME \
153142
--tracing-config Mode=Active
154143
```
155144

156-
You can now test the function using the AWS CLI or the AWS Lambda console
145+
Test the function using the AWS CLI:
157146

158147
```bash
159148
$ aws lambda invoke
@@ -174,8 +163,7 @@ making log management and aggregation more efficient at scale. More details on h
174163
and level refer to the article.
175164
https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/
176165

177-
To log lambda function code, use the global Log object with extension functions. The log message
178-
accepts any object / primitive type.
166+
Use the global Log object with extension functions. The log message accepts any object / primitive type.
179167

180168
```kotlin
181169
Log.trace(message: T?) // The most fine-grained information used to trace the path of your code's execution
@@ -191,23 +179,14 @@ Log.error(message: T?) // Messages about problems that prevent the code from per
191179
Log.fatal(message: T?) // Messages about serious errors that cause the application to stop functioning
192180
```
193181

194-
## Troubleshoot
195-
196-
- If you're going to use Amazon Linux 2023 machine, you'll need to create
197-
a [lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html) with
198-
libcrypt.so dependency. This is a dynamic library and seems not included into Amazon Linux 2023
199-
container. The lybcrypt.so can be taken directly from your linux machine (e.g. from
200-
/lib/x86_64-linux-gnu/libcrypt.so.1 ) or via the
201-
following [Github Action workflow](https://github.com/trueangle/kotlin-native-aws-lambda-runtime/actions/workflows/libcrypt.yml).
202-
Once retrieved, zip it and upload as a layer to your lambda function.
182+
## Troubleshooting
203183

204-
- For the time being, only x86-64 architecture is supported by the runtime. LinuxArm64 is not
205-
supported by Kotlin Native still, details:
184+
- For Amazon Linux 2023, create a [Lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html) with the libcrypt.so dependency. This library can be taken from your Linux machine or via the [Github Action workflow](https://github.com/trueangle/kotlin-native-aws-lambda-runtime/actions/workflows/libcrypt.yml).
185+
- Currently, only x86-64 architecture is supported by the runtime. LinuxArm64 is not supported by Kotlin Native yet, For more details, see:
206186
1. The list of supported targets for Kotlin Native (
207187
2.0.20-RC2) https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.20-RC2/
208-
2. Opened
209-
issue: https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
210-
- If you are running the project build on MacOs you might come across a set of errors connected with
188+
2. https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native
189+
- If you are running the project build on MacOS you might come across a set of errors connected with
211190
curl linking e.g. `ld.lld: error: undefined symbol: curl_global_init`. This means that your local
212191
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).
213192
To solve that either

0 commit comments

Comments
 (0)