Skip to content

ClientContext

reference
1 min readUpdated

Kind: Interface

Source: src/adapter/aws-lambda/types.ts

Part of: Adapter

ClientContext defines the request-scoped context passed through the AWS Lambda adapter. It groups the platform client API, environment values, and an open-ended Custom field for application-specific context.

Properties

PropertyType
clientClientContextClient
Customany
envClientContextEnv

Diagram

mermaid
graph LR
  Context[ClientContext]
  Client[client: ClientContextClient]
  Env[env: ClientContextEnv]
  Custom[Custom: any]

  Context --> Client
  Context --> Env
  Context --> Custom

Usage

ts
import type { ClientContext } from "./types";

function handleRequest(context: ClientContext) {
  const region = context.env.region;

  context.client.log({
    message: `Handling request in ${region}`,
  });

  const tenantId = context.Custom?.tenantId;

  return {
    tenantId,
    region,
  };
}

AI Coding Instructions

  • Pass ClientContext through Lambda request handling code instead of separately passing client, env, and custom values.
  • Access AWS adapter APIs through context.client and configuration through context.env.
  • Treat Custom as application-defined data; narrow or validate its shape before reading properties.
  • Keep custom context values request-scoped to avoid sharing mutable state across Lambda invocations.

How it works

ClientContext is an exported TypeScript interface that describes the clientContext value on an AWS Lambda LambdaContext. That enclosing property is optional and may be undefined. src/adapter/aws-lambda/types.ts:8-13 src/adapter/aws-lambda/types.ts:35-47

Its required members are:

It also declares an optional, capitalized Custom member with the any type. src/adapter/aws-lambda/types.ts:11

The interface declares no methods, runtime validation, thrown errors, or side effects. src/adapter/aws-lambda/types.ts:8-13 The AWS Lambda adapter passes its received LambdaContext onward as context in streamHandle and as lambdaContext in handle; neither shown path reads clientContext directly. src/adapter/aws-lambda/handler.ts:147-157 src/adapter/aws-lambda/handler.ts:252-272

Was this page helpful?

Download as PDF
ClientContext — Hono (narrator proof)