Skip to Content
platform-guidesAws Lambda

Last Updated: 3/11/2026


AWS Lambda

AWS Lambda  is a serverless platform by Amazon Web Services. Hono works on AWS Lambda with Node.js 18+ using the AWS Lambda adapter.

Setup

Use AWS CDK  to set up functions, IAM roles, and API Gateway:

mkdir my-app cd my-app cdk init app -l typescript npm install hono npm install -D esbuild mkdir lambda touch lambda/index.ts

Hello World

Edit lambda/index.ts:

import { Hono } from 'hono' import { handle } from 'hono/aws-lambda' const app = new Hono() app.get('/', (c) => c.text('Hello Hono!')) export const handler = handle(app)

Deploy

Edit lib/my-app-stack.ts:

import * as cdk from 'aws-cdk-lib' import { Construct } from 'constructs' import * as lambda from 'aws-cdk-lib/aws-lambda' import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs' export class MyAppStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props) const fn = new NodejsFunction(this, 'lambda', { entry: 'lambda/index.ts', handler: 'handler', runtime: lambda.Runtime.NODEJS_22_X, }) const fnUrl = fn.addFunctionUrl({ authType: lambda.FunctionUrlAuthType.NONE, }) new cdk.CfnOutput(this, 'lambdaUrl', { value: fnUrl.url!, }) } }

Deploy:

cdk deploy

Binary Data

Hono automatically encodes binary responses to base64:

app.get('/image', async (c) => { const buffer = await getImageBuffer() c.header('Content-Type', 'image/png') return c.body(buffer) // Automatically base64 encoded })

Access Lambda Context

Access AWS Lambda events and context:

import { Hono } from 'hono' import type { LambdaEvent, LambdaContext } from 'hono/aws-lambda' import { handle } from 'hono/aws-lambda' type Bindings = { event: LambdaEvent lambdaContext: LambdaContext } const app = new Hono<{ Bindings: Bindings }>() app.get('/info', (c) => { return c.json({ isBase64Encoded: c.env.event.isBase64Encoded, awsRequestId: c.env.lambdaContext.awsRequestId, }) }) export const handler = handle(app)

Request Context

Access API Gateway request context:

import type { LambdaEvent } from 'hono/aws-lambda' type Bindings = { event: LambdaEvent } const app = new Hono<{ Bindings: Bindings }>() app.get('/context', (c) => { const context = c.env.event.requestContext return c.json(context) })

Response Streaming

Enable Lambda response streaming :

// In CDK stack fn.addFunctionUrl({ authType: lambda.FunctionUrlAuthType.NONE, invokeMode: lambda.InvokeMode.RESPONSE_STREAM, })

Use streamHandle:

import { streamHandle } from 'hono/aws-lambda' import { streamText } from 'hono/streaming' const app = new Hono() app.get('/stream', async (c) => { return streamText(c, async (stream) => { for (let i = 0; i < 3; i++) { await stream.writeln(`Chunk ${i}`) await stream.sleep(1000) } }) }) export const handler = streamHandle(app)