Recipes
Serverless
Run the HTTP application behind AWS Lambda.
ServerlessHttp answers API Gateway and Lambda function URL events with your whole HTTP pipeline (middleware, guards, pipes, validation, filters), with no socket:
class Handler : RequestStreamHandler {
override fun handleRequest(input: InputStream, output: OutputStream, context: Context) =
output.write(app.handle(input.readBytes().decodeToString()).encodeToByteArray())
companion object {
val app = ServerlessHttp(Kest.create<AppModule>()) { enableCors(); usePipes(ValidationPipe::class) } // once per Lambda container
}
}Supported events: API Gateway REST API (v1), HTTP API (v2) and function URLs. Query strings, headers, cookies, base64 bodies and Set-Cookie are mapped both ways. Binary and compressed responses come back base64-encoded.
Honest limits
- WebSockets, Server-Sent Events and other streaming responses do not work (a streamed body is collected and returned whole).
- A JVM cold start takes hundreds of milliseconds to seconds. Compile-time wiring avoids classpath scanning, which helps, but use SnapStart or provisioned concurrency for latency-sensitive functions. A GraalVM native image has not been tried.
- It has been tested with Kest's own event fixtures, not deployed to a real Lambda.