Kotlin Multiplatform library for AWS Lambda. Targets: jvm, js (Node.js), linuxX64, linuxArm64, macosArm64. The runtime module has no js target: the Node.js Lambda runtime polls for events itself.
The ktor module serves API Gateway proxy events with a Ktor application, in-process and without sockets:
fun Application.module() {
routing {
get("/hello/{name}") { call.respondText("Hello ${call.parameters["name"]}") }
}
}
// HTTP API (payload 2.0); use KtorApiGatewayProxyV1Handler for REST APIs (payload 1.0).
class Handler : KtorApiGatewayProxyV2Handler(Application::module)The handler is an ordinary suspending handler, so it deploys like any other on every target. Routes reach the invocation via call.lambdaContext and the raw event via call.attributes[ApiGatewayProxyV2EventKey]. Response bodies that are valid UTF-8 go back as text, anything else as base64. WebSockets and streaming responses are not supported.
Build a Linux executable and start the custom runtime from main:
// build.gradle.kts
kotlin {
linuxArm64 {
binaries.executable {
entryPoint = "com.example.main"
baseName = "bootstrap"
// platform.posix links libcrypt.so.1, which the provided.al2023 runtime lacks.
linkerOpts("-Wl,--as-needed")
}
}
}fun main() = LambdaNativeRuntime.BufferedResponse(MyHandler()).start()Deploy the resulting bootstrap.kexe as bootstrap on the provided.al2023 runtime.
Export a function that delegates to your handler and deploy the compiled output on a nodejs runtime, with <module>.handler as the handler:
// build.gradle.kts
kotlin {
js {
nodejs()
binaries.library()
useCommonJs()
}
}@JsExport
fun handler(event: Any?, context: NodeLambdaContext): Promise<Any?> = MyHandler.handleNode(event, context)Blocking handlers return the result directly instead of a Promise.