Quick Start
Create a new Hono project for AWS Lambda: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 atemplate.yaml:
template.yaml
AWS CDK
Create a Lambda function with CDK:Serverless Framework
Create aserverless.yml:
serverless.yml
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
Keep package size small
Keep package size small
Lambda has size limits. Minimize dependencies and use tree-shaking.
Use provisioned concurrency for latency-sensitive apps
Use provisioned concurrency for latency-sensitive apps
Reduce cold starts with provisioned concurrency.
Implement health checks
Implement health checks
Add a
/health endpoint for monitoring.Use environment variables for configuration
Use environment variables for configuration
Store API keys and configuration in environment variables.
Enable X-Ray tracing
Enable X-Ray tracing
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