Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

4 watching

Forks

Repository files navigation

aws-lambda-kotlin

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.

Ktor

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.

Kotlin/Native

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.

Node.js

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages