# CognitoIdentity

**Kind:** Interface

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

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

`CognitoIdentity` describes the Amazon Cognito identity attached to an AWS Lambda request. It carries the identity ID and the Cognito identity pool ID so adapter code can read the caller's Cognito context.

## Properties

| Property | Type |
|---|---|
| `cognitoIdentityId` | `string` |
| `cognitoIdentityPoolId` | `string` |

## Diagram

```mermaid
graph LR
  Request[AWS Lambda request] --> Identity[CognitoIdentity]
  Identity --> IdentityId[cognitoIdentityId]
  Identity --> PoolId[cognitoIdentityPoolId]
```

## Usage

```ts
import type { CognitoIdentity } from './types'

function getIdentityContext(identity: CognitoIdentity) {
  return {
    identityId: identity.cognitoIdentityId,
    poolId: identity.cognitoIdentityPoolId,
  }
}

const identity: CognitoIdentity = {
  cognitoIdentityId: 'identity-value',
  cognitoIdentityPoolId: 'pool-value',
}

const context = getIdentityContext(identity)
```

## AI Coding Instructions

- Keep both interface properties as strings.
- Read `cognitoIdentityId` when request handling needs the Cognito caller identity.
- Read `cognitoIdentityPoolId` when code needs to distinguish the originating identity pool.
- Handle missing Cognito context before constructing or consuming this interface when Lambda events may be unauthenticated.

## How it works

`CognitoIdentity` is an exported TypeScript interface with two required string fields:

- `cognitoIdentityId`: a string. [`src/adapter/aws-lambda/types.ts:3-5`](src/adapter/aws-lambda/types.ts#L3-L5)
- `cognitoIdentityPoolId`: a string. [`src/adapter/aws-lambda/types.ts:3-6`](src/adapter/aws-lambda/types.ts#L3-L6)

It is used as the optional `identity` member of `LambdaContext`; a handler context may therefore omit it, or contain an object matching this interface. [`src/adapter/aws-lambda/types.ts:35-45`](src/adapter/aws-lambda/types.ts#L35-L45)

The interface declares no methods, runtime validation, thrown errors, or side effects. [`src/adapter/aws-lambda/types.ts:3-6`](src/adapter/aws-lambda/types.ts#L3-L6)
