template.yamlyaml
Transform:
- AWS::Serverless-2016-10-31
- KhoneGateway
Resources:
GatewayService:
Type: Khone::Gateway::Service
Properties:
CapacityProviderArn: !Ref GatewayCapacityProviderArn
MemorySize: 2048
Timeout: 30
ExecutionEnvironmentMemoryGiBPerVCpu: 2.0
PerExecutionEnvironmentMaxConcurrency: 64
ConfigPrefix: !Sub "khone/${AWS::StackName}/gateway/"
GatewayConfig:
DefaultTimeoutMs: 2000
Spec:
openapi: 3.0.0
paths:
/items/{id}:
get:
x-target-lambda: !GetAtt ItemsFn.Arn
x-khone:
maxBatchSize: 16
maxWaitMs: 35
invokeMode: response_stream
handler.js (Mode B)javascript
const { batchAdapter } = require("khone-lambda-adapter");
// Single-request handler shape - preserved.
async function handleItem(event) {
const item = await db.get(event.pathParameters.id);
return {
statusCode: 200,
headers: { "content-type": "application/json" },
body: JSON.stringify(item),
};
}
// Adapter handles batch correlation, per-item errors,
// and the NDJSON response framing.
exports.handler = batchAdapter(handleItem);