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
45A runtime for executing AWS Lambda Functions powered by Kotlin Native, designed to mitigate known
56cold start issues associated with the JVM platform.
67
78Project 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
1314The runtime supports the
@@ -23,5 +24,75 @@ Linux 2023 (x86_64) with 1024MB of memory, ranks among the top 5 fastest cold st
2324performance is on par with Python and .NET implementations. For a comparison with other languages (
2425including 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
0 commit comments