SDK adapters
Adapters convert normal single-request handlers into batch handlers compatible with the gateway.
Two adapters are available: Node (khone-lambda-adapter) and Rust (khone-lambda-adapter).
Node adapter
Package: khone-lambda-adapter (CommonJS; main: dist/index.js).
Buffered
const { batchAdapter } = require("khone-lambda-adapter");
exports.handler = batchAdapter(async function handler(event) {
return { statusCode: 200, body: "ok" };
});batchAdapter(handler, options?) accepts an options object:
| Option | Type | Default | Description |
|---|---|---|---|
concurrency | number | 16 | Maximum concurrent in-flight handler invocations across the batch. |
Streaming
const { batchAdapterStream } = require("khone-lambda-adapter");
exports.handler = batchAdapterStream(handler);Interleaved streaming is enabled with:
exports.handler = batchAdapterStream(handler, { interleaved: true });batchAdapterStream(handler, options?) options:
| Option | Type | Default | Description |
|---|---|---|---|
concurrency | number | 16 | Maximum concurrent in-flight handler invocations. |
interleaved | boolean | false | Emit head/chunk/end/error records per request. |
streamifyResponse | function | globalThis.awslambda.streamifyResponse | Override the runtime streaming wrapper. |
Streaming requires awslambda.streamifyResponse from the AWS managed Node.js runtime, or an
explicit streamifyResponse override. The adapter throws if neither is available.
Rust adapter
Crate: khone-lambda-adapter (publish = false; depend via git or path).
Buffered
use khone_lambda_adapter::{batch_adapter, HandlerResponse};
let adapter = batch_adapter(handler).with_concurrency(16);
let response = adapter.handle(event, &ctx).await;batch_adapter(handler) returns a BatchAdapter with:
.with_concurrency(usize)— defaults to16.
Streaming
use khone_lambda_adapter::batch_adapter_stream;
let adapter = batch_adapter_stream(handler).with_interleaved(true);batch_adapter_stream(handler) returns a BatchAdapterStream with:
.with_concurrency(usize)— defaults to16..with_interleaved(bool)— defaults tofalse.
Response mapping
- Each batch item becomes an API Gateway HTTP API v2 event.
requestContext.requestIdis the response correlation id.- Handler errors become per-item
500responses withcontent-type: text/plainandinternal erroras the body. headers,cookies,body, andisBase64Encodedfollow the standard Lambda response shape.- The Rust adapter clamps
statusCode == 0to200for safety.