๐ Lambda API with Hono
A minimal and powerful REST API built using Hono and deployed to AWS Lambda. This setup includes a full development workflow, local testing with tsx, and automated deployment using the AWS CLI.
๐งฐ Prerequisites: Set Up AWS Lambda
- Go to the AWS Console โ Lambda โ Create function.
- Choose Author from scratch.
- Give your Lambda function a name, e.g.,
lambda-api-hono-learning. - Set your desired timeout (e.g., 10 seconds).
- Set your desired memory allocation (e.g., 256 MB).
- Click Create Function.
๐ ๏ธ Optional: AWS CLI Setup (One-Time Only)
- Go to AWS IAM and create a new IAM user.
- Attach the AdministratorAccess policy (since this is your private laptop).
- Generate an Access Key ID and Secret Access Key.
- Choose Command Line Interface (CLI) as the usage method.
- On your terminal, run:
- Enter your Access Key ID
- Enter your Secret Access Key
- Enter your default region name (e.g.,
us-east-1) - Enter your default output format (recommended:
json)
AWS CLI configuration is now complete.
๐ Project Structure
.
โโโ src/
โ โโโ index.js # Main API logic (Hono app)
โโโ runlocal.js # Starts server locally using @hono/node-server
โโโ dist/ # Build output (after bundling)
โโโ lambda.zip # Zip file for Lambda upload
โโโ temp-deploy-logs/ # Deployment logs with timestamps
โโโ package.json
๐ Quick Start
1. Clone and Install
git clone <your-repo-url> cd lambda-api-hono-learning npm install
๐งช Local Development
Test your Hono app locally using tsx and @hono/node-server.
1. Start the server
The server will run at:
Test endpoints like:
GET /add/2/3GET /subtract/5/1GET /multiply/4/2GET /divide/8/2GET /test-query-data?name=JohnPOST /test-form-datawith JSON body
โ๏ธ AWS Lambda Deployment
1. Modify the Function Name and Region
Edit the update script in package.json:
"update": "... --function-name <your-lambda-function-name> --region <your-region> ..."
2. Deploy with One Command
This runs:
buildโ Bundle the app using esbuildzipโ Createlambda.zipfrom the bundleupdateโ Upload it to your Lambda function- Saves logs in
temp-deploy-logs/output_<timestamp>.log
Ensure your Lambda handler is set to
index.handlerand runtime tonode.js 20.x.
๐ Customize
- Change API logic in
src/index.js - For more routes and features, refer to: Hono Docs
๐ Resources
- Hono Docs: https://hono.dev/docs/
- AWS CLI Docs: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-quickstart.html
- Lambda Docs: https://docs.aws.amazon.com/lambda/latest/dg/welcome.html
๐ Template made by
Preet Jariwala โค๏ธ
๐ License
MIT