Skip to content

CognitoIdentity

reference
1 min readUpdated

Kind: Interface

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

Part of: 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

PropertyType
cognitoIdentityIdstring
cognitoIdentityPoolIdstring

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:

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

The interface declares no methods, runtime validation, thrown errors, or side effects. src/adapter/aws-lambda/types.ts:3-6

Was this page helpful?

Download as PDF
CognitoIdentity — Hono (narrator proof)