Skip to main content
The AWS Lambda adapter converts Hono applications into AWS Lambda handlers that work with API Gateway, ALB, Lambda Function URLs, and VPC Lattice.

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 instance
  • options - 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

Returns false for:
  • text/* (text/plain, text/html, text/css, text/javascript, text/csv)
  • Content types containing json or xml (including application/json, application/xml, +json, +xml)
Returns true for all other content types.

getConnInfo()

Extracts connection information from AWS Lambda events.
Works with multiple event sources:
  • API Gateway v1 (REST API): requestContext.identity.sourceIp
  • API Gateway v2 (HTTP API/Function URLs): requestContext.http.sourceIp
  • ALB: Falls back to x-forwarded-for header

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 through c.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:
  1. Content-Type header (via isContentTypeBinary option)
  2. 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 cookies array in the response
  • API Gateway v1: Uses multiValueHeaders['set-cookie']
  • ALB: Depends on multi-value headers configuration

Deployment

Using AWS SAM

Using AWS CDK

Using Serverless Framework

See Also