Import
Functions
handle()
Converts a Hono application to an AWS Lambda handler. Accepts events from API Gateway (v1 and v2), Application Load Balancer (ALB), Lambda Function URLs, and VPC Lattice.Parameters
app- The Hono application instanceoptions- Optional configuration:isContentTypeBinary-(contentType: string) => boolean- Function to determine if content should be base64 encoded
Returns
Lambda handler function compatible with API Gateway, ALB, and Function URLs.Example
Custom Binary Content Detection
streamHandle()
Creates a streaming Lambda handler that uses response streaming for better performance with large responses.Streaming responses require Lambda function URLs or API Gateway HTTP APIs configured for streaming. This feature requires the AWS Lambda runtime to support response streaming.
Example
defaultIsContentTypeBinary()
Default function to determine if a content type should be base64 encoded.Returns
true if the content type is binary, false otherwise.
Logic
Returnsfalse for:
text/*(text/plain, text/html, text/css, text/javascript, text/csv)- Content types containing
jsonorxml(includingapplication/json,application/xml,+json,+xml)
true for all other content types.
getConnInfo()
Extracts connection information from AWS Lambda events.- API Gateway v1 (REST API):
requestContext.identity.sourceIp - API Gateway v2 (HTTP API/Function URLs):
requestContext.http.sourceIp - ALB: Falls back to
x-forwarded-forheader
Returns
Example
Types
LambdaEvent
Union type of all supported Lambda event types:APIGatewayProxyResult
Lambda response format for API Gateway:Request Context Types
ApiGatewayRequestContext
API Gateway REST API (v1) request context:ApiGatewayRequestContextV2
API Gateway HTTP API (v2) and Function URLs request context:ALBRequestContext
Application Load Balancer request context:LambdaContext
AWS Lambda runtime context:Accessing Lambda Context
The Lambda event and context are available throughc.env:
Platform-Specific Notes
Event Sources
The adapter automatically detects and handles:- API Gateway REST API (v1): Traditional REST APIs with resource-based routing
- API Gateway HTTP API (v2): Lower latency, lower cost HTTP APIs
- Lambda Function URLs: Direct HTTPS endpoints for Lambda functions
- Application Load Balancer: ALB target integrations
- VPC Lattice: Service mesh integrations
Binary Content
Binary responses are automatically base64 encoded based on:- Content-Type header (via
isContentTypeBinaryoption) - Content-Encoding header (gzip, deflate, compress, br)
Headers
- Single-value headers: Used by default and API Gateway v2
- Multi-value headers: Used when the event includes
multiValueHeaders
Cookies
- API Gateway v2: Uses the
cookiesarray in the response - API Gateway v1: Uses
multiValueHeaders['set-cookie'] - ALB: Depends on multi-value headers configuration