Skip to main content
AWS Lambda is a serverless compute service that runs your code in response to events. Hono provides a robust adapter for AWS Lambda with support for API Gateway, ALB, and Lambda Function URLs.

Quick Start

Create a new Hono project for AWS Lambda:
Select “aws-lambda” as your template when prompted.

Installation

Add Hono to your existing AWS Lambda project:

Basic Usage

Create your application and wrap it with the Lambda handler:
index.ts
The handle adapter converts your Hono app into an AWS Lambda handler that works with API Gateway v1, API Gateway v2, ALB, and Lambda Function URLs.

Event Sources

The Hono adapter automatically detects and handles different event sources:

API Gateway v1 (REST API)

API Gateway v2 (HTTP API)

Application Load Balancer (ALB)

The adapter handles ALB events with multi-value headers:

Lambda Function URLs

Streaming Responses

For Lambda Response Streaming (Node.js 20+):
Streaming requires Lambda Response Streaming to be enabled in your function configuration.

Accessing Lambda Context

Access the Lambda event and context:

Connection Info

Get connection information:

Binary Content

Handle binary responses (images, PDFs, etc.):

Environment Variables

Access Lambda environment variables:

Deployment

AWS SAM

Create a template.yaml:
template.yaml
Deploy:

AWS CDK

Create a Lambda function with CDK:

Serverless Framework

Create a serverless.yml:
serverless.yml
Deploy:

Lambda Function URLs

1

Build your function

2

Create deployment package

3

Deploy to Lambda

4

Create Function URL

Project Structure

Build Configuration

Optimize your build for Lambda:
tsconfig.json
package.json

Best Practices

Lambda has size limits. Minimize dependencies and use tree-shaking.
Reduce cold starts with provisioned concurrency.
Add a /health endpoint for monitoring.
Store API keys and configuration in environment variables.
Use AWS X-Ray for debugging and performance analysis.

Performance Tips

  • Use Node.js 20+ for best performance
  • Enable arm64 architecture for better price/performance
  • Optimize memory allocation (more memory = more CPU)
  • Use Lambda Layers for shared dependencies
  • Implement connection pooling for databases

Resources

AWS Lambda Docs

Official AWS Lambda documentation

API Gateway

Learn about API Gateway integration