Skip to content

About

Run Hono apps on AWS Lambda: API Gateway v1/v2, ALB, function URLs and non-HTTP triggers (S3, SQS) via route-based trigger factories.

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Repository files navigation

hono-adapter-aws-lambda TypeScript heart icon

npm version npm downloads Codecov Bundlejs jsDocs.io

hono-adapter-aws-lambda is a fork of hono's aws-lambda adapter, experimenting and adding some extra features

Features, Changes & Roadmap

  • Codebase is refactored quite a bit.
  • Add routing support for trigger events.
    • I.e, support for S3, SQS, etc. triggers, which would also support a simpler cross-function call interface.

    • Multiple routes on the same eventSource support.
    • Uses a factory pattern, the internal trigger context (middlewares, env bindings) is decoupled from the main Hono app.
    • See #10 for more information.
  • Support returning a Lambda response result directly, useful for returning the response of another invoked function.

Usage

Install package:

# pnpm (recommended)
pnpm install hono-adapter-aws-lambda

Import:

// ESM
import { handle, streamHandle } from 'hono-adapter-aws-lambda'

Examples:

Fast example of accepting an S3 trigger event

import type { S3Event } from 'aws-lambda' // You need to install `@types/aws-lambda`
import { createTriggerFactory, handle, streamHandle } from 'hono-adapter-aws-lambda'

interface Bindings {
  event: { Records: Array<{ eventName: string }> }
}
const app = new Hono<{ Bindings: Bindings }>()
const triggerFactory = createTriggerFactory(app)

triggerFactory.on('aws:s3', '$!', c => c.text((c.env.event as S3Event).Records[0].eventName))

See some more examples in the test file: test/index.test.ts

Releasing

Releases are manual and version-first: the version is an input, not decided by the workflow.

  1. Run Actions → Release → Run workflow, enter the version to ship without a leading v (e.g. 1.5.0) and optionally tick dry-run to stop before pushing/publishing.
  2. The workflow validates the version, runs pnpm run check, builds, then changelogen bumps package.json, writes CHANGELOG.md, commits and tags v<version>.
  3. It pushes the commit and tag, creates the GitHub release from the changelog section, and publishes to npm with provenance over trusted publishing (OIDC, no token).

A pushed tag does not publish anything — only this dispatch does. Locally you can validate a version with pnpm run release:check 1.5.0 and preview the next changelog with pnpm run release:preview.

Before the first automated release: publish the package once by hand, then on npmjs.com open the package's Settings → Trusted Publisher and add this repository with the workflow filename release.yml.

License

MIT License © 2024 NamesMT

About

Run Hono apps on AWS Lambda: API Gateway v1/v2, ALB, function URLs and non-HTTP triggers (S3, SQS) via route-based trigger factories.

Topics

Resources

Stars

10 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages