# LambdaContext

**Kind:** Interface

**Source:** [`src/adapter/aws-lambda/types.ts`](https://github.com/honojs/hono/blob/main/src/adapter/aws-lambda/types.ts#L35)

**Part of:** [Adapter](subsystem-src-adapter)

Handler context parameter.
See ://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation.

`LambdaContext` models the context parameter passed to an AWS Lambda handler. It contains invocation metadata, runtime settings, optional Cognito identity and client context data, and a method for checking the remaining execution time.

## Properties

| Property | Type |
|---|---|
| `callbackWaitsForEmptyEventLoop` | `boolean` |
| `functionName` | `string` |
| `functionVersion` | `string` |
| `invokedFunctionArn` | `string` |
| `memoryLimitInMB` | `string` |
| `awsRequestId` | `string` |
| `logGroupName` | `string` |
| `logStreamName` | `string` |
| `identity` | `CognitoIdentity | undefined` |
| `clientContext` | `ClientContext | undefined` |

## Diagram

```mermaid
graph LR
  Handler["Lambda handler"] --> Context["LambdaContext"]
  Context --> Invocation["Invocation metadata"]
  Context --> Runtime["Runtime settings"]
  Context --> Identity["CognitoIdentity | undefined"]
  Context --> Client["ClientContext | undefined"]
  Context --> Remaining["getRemainingTimeInMillis()"]
```

## Usage

```ts
import type { LambdaContext } from './types';

export async function handler(
  event: { action?: string },
  context: LambdaContext,
) {
  console.log({
    requestId: context.awsRequestId,
    functionName: context.functionName,
    invokedFunctionArn: context.invokedFunctionArn,
    remainingTime: context.getRemainingTimeInMillis(),
  });

  if (context.getRemainingTimeInMillis() <= 0) {
    throw new Error('Lambda execution time has expired.');
  }

  context.callbackWaitsForEmptyEventLoop = false;

  return {
    requestId: context.awsRequestId,
    action: event.action,
  };
}
```

## AI Coding Instructions

- Accept `LambdaContext` as the handler context parameter when adapter code needs AWS Lambda invocation metadata.
- Call `getRemainingTimeInMillis()` before work that may exceed the Lambda execution limit.
- Treat `identity` and `clientContext` as optional values and check for `undefined` before reading their properties.
- Set `callbackWaitsForEmptyEventLoop` only when the handler should return before the Node.js event loop is empty.
- Keep AWS-specific context handling inside the Lambda adapter boundary.
