Skip to content

Commit 478ac73

Browse files
committed
Update markdown
1 parent 498031e commit 478ac73

File tree

5 files changed

+76
-24
lines changed

5 files changed

+76
-24
lines changed

README.md

Lines changed: 75 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# Kotlin Native Runtime for AWS Lambda
2+
23
[![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)
34

45
A runtime for executing AWS Lambda Functions powered by Kotlin Native, designed to mitigate known
56
cold start issues associated with the JVM platform.
67

78
Project structure:
89

9-
- lambda-runtime — is a library that provides a Lambda runtime.
10-
- lambda-events — is a library with strongly-typed Lambda event models, such
10+
- `lambda-runtime` — is a library that provides a Lambda runtime.
11+
- `lambda-events` — is a library with strongly-typed Lambda event models, such
1112
as `APIGatewayRequest`, `DynamoDBEvent`, `S3Event`, `KafkaEvent`, `SQSEvent` and so on.
1213

1314
The runtime supports the
@@ -23,5 +24,75 @@ Linux 2023 (x86_64) with 1024MB of memory, ranks among the top 5 fastest cold st
2324
performance is on par with Python and .NET implementations. For a comparison with other languages (
2425
including Java), visit https://maxday.github.io/lambda-perf/.
2526

26-
![screenshot](docs/performance_hello_world.png)
27-
<img src="" alt="Kotlin Native AWS Lambda Runtime benchmarks" width="800"/>
27+
![Kotlin Native AWS Lambda Runtime benchmarks](docs/performance_hello_world.png)
28+
29+
## Getting started
30+
31+
There are two types of lambda functions:
32+
33+
### Buffered handler
34+
35+
tbd
36+
37+
### Streaming handler
38+
39+
tbd
40+
41+
## Testing Runtime locally
42+
43+
To run local runtime
44+
locally [aws runtime emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator) is
45+
used:
46+
47+
1. `./gradlew build` to build lambda executable
48+
2. Modify runtime-emulator/Dockerfile to set proper path to the generated executable (.kexe) file,
49+
located in build/bin/linuxX64/releaseExecutable
50+
3. Run `docker build -t sample:latest .`
51+
4. Start server `docker run -p 9000:8080 sample:latest`
52+
5. Execute function
53+
via `curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'`
54+
6. `docker ps; docker stop CONTAINER_ID` to stop the execution
55+
56+
## Build and deploy to AWS
57+
58+
## Logging
59+
60+
The Runtime uses AWS logging conventions for enhanced log capture, supporting String and JSON log output
61+
format. It also allows you to dynamically control log levels without altering your code, simplifying
62+
the debugging process. Additionally, you can direct logs to specific Amazon CloudWatch log groups,
63+
making log management and aggregation more efficient at scale. More details on how to set log format and level refer to the article.
64+
https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/
65+
66+
To log lambda function code, use the global Log object with extension functions. The log message accepts any object / primitive type.
67+
68+
```
69+
Log.trace(message: T?) // The most fine-grained information used to trace the path of your code's execution
70+
71+
Log.debug(message: T?) // Detailed information for system debugging
72+
73+
Log.info(message: T?) // Messages that record the normal operation of your function
74+
75+
Log.warn(message: T?) // Messages about potential errors that may lead to unexpected behavior if unaddressed
76+
77+
Log.error(message: T?) // Messages about problems that prevent the code from performing as expected
78+
79+
Log.fatal(message: T?) // Messages about serious errors that cause the application to stop functioning
80+
```
81+
82+
83+
## Troubleshoot
84+
85+
- If you're going to use Amazon Linux 2023 machine, you'll need to create
86+
a [lambda layer](https://docs.aws.amazon.com/lambda/latest/dg/chapter-layers.html) with
87+
libcrypt.so dependency. This is a dynamic library and seems not included into Amazon Linux 2023
88+
container. The lybcrypt.so can be taken directly from your linux machine (e.g. from
89+
/lib/x86_64-linux-gnu/libcrypt.so.1 ) or via the
90+
following [Github Action workflow](https://github.com/trueangle/kotlin-native-aws-lambda-runtime/actions/workflows/libcrypt.yml).
91+
Once retrieved, zip it and upload as a layer to your lambda function.
92+
93+
- For the time being, only x86-64 architecture is supported by the runtime. LinuxArm64 is not
94+
supported by Kotlin Native still, details:
95+
1. The list of supported targets for Kotlin Native (
96+
2.0.20-RC2) https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.20-RC2/
97+
2. Opened
98+
issue: https://youtrack.jetbrains.com/issue/KT-36871/Support-Aarch64-Linux-as-a-host-for-the-Kotlin-Native

runtime-emulator/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
FROM public.ecr.aws/lambda/provided:al2
22

3-
#todo file name
43
COPY sample/build/bin/linuxX64/releaseExecutable/sample.kexe /var/runtime/bootstrap
54

65
COPY large-file.json /var/task/large-file.json

sample/src/nativeMain/kotlin/com/github/trueangle/knative/lambda/runtime/sample/handler/ObjectBodyLambdaHandler.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ import kotlinx.serialization.Serializable
88

99
class ObjectBodyLambdaHandler : LambdaBufferedHandler<APIGatewayV2Request, APIGatewayV2Response> {
1010
override suspend fun handleRequest(input: APIGatewayV2Request, context: Context): APIGatewayV2Response {
11-
/* Log.info(input)
12-
Log.info(context)
13-
Log.fatal(RuntimeException())*/
14-
//Log.info(input.question + "\n answer is Hello world")
15-
1611
return APIGatewayV2Response(
1712
statusCode = 200,
18-
body = "\n answer is Hello world",
13+
body = "Answer is Hello world",
1914
cookies = null,
2015
headers = null,
2116
isBase64Encoded = false

sample/src/nativeMain/kotlin/com/github/trueangle/knative/lambda/runtime/sample/handler/SampleStreamingHandler.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,9 @@ package com.github.trueangle.knative.lambda.runtime.sample.handler
22

33
import io.github.trueangle.knative.lambda.runtime.api.Context
44
import io.github.trueangle.knative.lambda.runtime.handler.LambdaStreamHandler
5-
import io.ktor.utils.io.ByteChannel
65
import io.ktor.utils.io.ByteReadChannel
76
import io.ktor.utils.io.ByteWriteChannel
87
import io.ktor.utils.io.copyTo
9-
import io.ktor.utils.io.read
10-
import io.ktor.utils.io.readFully
11-
import io.ktor.utils.io.reader
12-
import io.ktor.utils.io.write
13-
import io.ktor.utils.io.writeSource
14-
import io.ktor.utils.io.writeStringUtf8
15-
import io.ktor.utils.io.writer
16-
import kotlinx.coroutines.GlobalScope
17-
import kotlinx.coroutines.coroutineScope
18-
import kotlinx.coroutines.currentCoroutineContext
19-
import kotlinx.coroutines.delay
208
import kotlinx.io.buffered
219
import kotlinx.io.files.Path
2210
import kotlinx.io.files.SystemFileSystem

sample/src/nativeMain/kotlin/com/github/trueangle/knative/lambda/runtime/sample/handler/StringBodyLambdaHandler.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.trueangle.knative.lambda.runtime.sample.handler
22

33
import io.github.trueangle.knative.lambda.runtime.api.Context
44
import io.github.trueangle.knative.lambda.runtime.handler.LambdaBufferedHandler
5-
import io.github.trueangle.knative.lambda.runtime.handler.LambdaHandler
65

76
class StringBodyLambdaHandler : LambdaBufferedHandler<String, String> {
87
override suspend fun handleRequest(input: String, context: Context): String {

0 commit comments

Comments
 (0)