Skip to content

namidapoo/hono-on-aws-lambda

Repository files navigation

hono-on-aws-lambda

This repository is an example of using AWS CDK to build an API Gateway and Lambda function with Hono.

Overview

This project demonstrates how to use the Hono web framework with AWS Lambda and API Gateway, utilizing AWS CDK for infrastructure as code.

Prerequisites

  • Node.js (v18 or higher)
  • AWS CDK (v2 or higher)
  • AWS Account with appropriate IAM permissions

Installation

  1. Clone the repository:

    git clone https://github.com/ve1997/hono-on-aws-lambda.git
    cd hono-on-aws-lambda
  2. Install dependencies

    npm install

Project Structure

  • lib/ : Contains the AWS CDK stack definition
  • lambda/ : Contains the Hono application code
  • types/: This includes exporting the AppType which is necessary when creating the Hono client object in the client repository
  • test/ : Contains tests for the Hono application

Usage

Deploying the Stack

  1. Synthesize the CloudFormation template
    cdk synth
  2. Deploy the stack
    cdk deploy

Testing

Run the tests using Vitest

npm run test

Example Endpoints

The following endpoints are available once the stack is deployed:

  • GET /: Returns a simple greeting message.
curl -i [your_endpoint]
  • GET /user/:id: Accepts a path parameter and returns a message including the user ID.
curl -i [your_endpoint]/user/123
  • GET /search: Accepts a query parameter and returns a message with the search query.
curl -i "[your_endpoint]/search?q=example"
  • POST /register: Accepts JSON data and returns a personalized message.
curl -i -X POST -H "Content-Type: application/json" -d @mock/rb.json [your_endpoint]/register

Replace [your_endpoint] with the actual endpoint URL provided by the cdk deploy command.

Used Stack

TypeScript Hono Zod Biome dotenv AWS Lambda APIGW

About

Deploying Lambda and API Gateway with CDK and Hono.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published