GitHub - preetramsha/lambda-api-hono-learning

2 min read Original article โ†—

๐Ÿš€ 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

  1. Go to the AWS Console โ†’ Lambda โ†’ Create function.
  2. Choose Author from scratch.
  3. Give your Lambda function a name, e.g., lambda-api-hono-learning.
  4. Set your desired timeout (e.g., 10 seconds).
  5. Set your desired memory allocation (e.g., 256 MB).
  6. Click Create Function.

๐Ÿ› ๏ธ Optional: AWS CLI Setup (One-Time Only)

  1. Go to AWS IAM and create a new IAM user.
  2. Attach the AdministratorAccess policy (since this is your private laptop).
  3. Generate an Access Key ID and Secret Access Key.
  4. Choose Command Line Interface (CLI) as the usage method.
  5. 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/3
  • GET /subtract/5/1
  • GET /multiply/4/2
  • GET /divide/8/2
  • GET /test-query-data?name=John
  • POST /test-form-data with 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 esbuild
  • zip โ€“ Create lambda.zip from the bundle
  • update โ€“ Upload it to your Lambda function
  • Saves logs in temp-deploy-logs/output_<timestamp>.log

Ensure your Lambda handler is set to index.handler and runtime to node.js 20.x.


๐Ÿ• Customize

  • Change API logic in src/index.js
  • For more routes and features, refer to: Hono Docs

๐Ÿ”— Resources


๐Ÿ˜† Template made by

Preet Jariwala โค๏ธ


๐Ÿ“ License

MIT