# AWS DynamoDB Stream Event

> AWS DynamoDB Streams event with record changes, keys, and stream view type.

- Name: `aws-dynamodb-stream-event`
- Categories: aws
- Detail page: https://open-types.dev/types/aws-dynamodb-stream-event

## Install

```bash
# Types only
npx shadcn add @open-types/aws-dynamodb-stream-event

# Types + Zod v4 validators
npx shadcn add @open-types/aws-dynamodb-stream-event-zod

# Types + real-world examples
npx shadcn add @open-types/aws-dynamodb-stream-event-examples
```

## Types

```typescript
export type AWSDynamoDBStreamViewType =
  | "KEYS_ONLY"
  | "NEW_IMAGE"
  | "OLD_IMAGE"
  | "NEW_AND_OLD_IMAGES";

export interface AWSDynamoDBStreamRecord {
  Keys: Record<string, Record<string, unknown>>;
  NewImage?: Record<string, Record<string, unknown>>;
  OldImage?: Record<string, Record<string, unknown>>;
  SequenceNumber: string;
  SizeBytes: number;
  StreamViewType: AWSDynamoDBStreamViewType;
}

export type AWSDynamoDBEventName = "INSERT" | "MODIFY" | "REMOVE";

export interface AWSDynamoDBEventRecord {
  eventID: string;
  eventName: AWSDynamoDBEventName;
  eventVersion: string;
  eventSource: string;
  awsRegion: string;
  dynamodb: AWSDynamoDBStreamRecord;
}

export interface AWSDynamoDBStreamEvent {
  Records: AWSDynamoDBEventRecord[];
}
```

## Zod validator

```typescript
import * as z from "zod";
import type {
  AWSDynamoDBStreamViewType,
  AWSDynamoDBStreamRecord,
  AWSDynamoDBEventName,
  AWSDynamoDBEventRecord,
  AWSDynamoDBStreamEvent,
} from "../types/aws-dynamodb-stream-event";

export const awsDynamoDbStreamViewTypeSchema = z.enum([
  "KEYS_ONLY",
  "NEW_IMAGE",
  "OLD_IMAGE",
  "NEW_AND_OLD_IMAGES",
]) satisfies z.ZodType<AWSDynamoDBStreamViewType>;

export const awsDynamoDbStreamRecordSchema = z.object({
  Keys: z.record(z.string(), z.record(z.string(), z.unknown())),
  NewImage: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
  OldImage: z.record(z.string(), z.record(z.string(), z.unknown())).optional(),
  SequenceNumber: z.string(),
  SizeBytes: z.number(),
  StreamViewType: awsDynamoDbStreamViewTypeSchema,
}) satisfies z.ZodType<AWSDynamoDBStreamRecord>;

export const awsDynamoDbEventNameSchema = z.enum([
  "INSERT",
  "MODIFY",
  "REMOVE",
]) satisfies z.ZodType<AWSDynamoDBEventName>;

export const awsDynamoDbEventRecordSchema = z.object({
  eventID: z.string(),
  eventName: awsDynamoDbEventNameSchema,
  eventVersion: z.string(),
  eventSource: z.string(),
  awsRegion: z.string(),
  dynamodb: awsDynamoDbStreamRecordSchema,
}) satisfies z.ZodType<AWSDynamoDBEventRecord>;

export const awsDynamoDbStreamEventSchema = z.object({
  Records: z.array(awsDynamoDbEventRecordSchema),
}) satisfies z.ZodType<AWSDynamoDBStreamEvent>;

export type {
  AWSDynamoDBStreamViewType,
  AWSDynamoDBStreamRecord,
  AWSDynamoDBEventName,
  AWSDynamoDBEventRecord,
  AWSDynamoDBStreamEvent,
} from "../types/aws-dynamodb-stream-event";
```

## Examples

```typescript
// Source: https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#with-ddb-create-test-function
// Captured: 2026-05
import type {
  AWSDynamoDBStreamViewType,
  AWSDynamoDBStreamRecord,
  AWSDynamoDBEventName,
  AWSDynamoDBEventRecord,
  AWSDynamoDBStreamEvent,
} from "../types/aws-dynamodb-stream-event";

export const awsDynamoDbStreamViewTypeExamples = {
  keysOnly: "KEYS_ONLY",
  newImage: "NEW_IMAGE",
  oldImage: "OLD_IMAGE",
  newAndOld: "NEW_AND_OLD_IMAGES",
} as const satisfies Record<string, AWSDynamoDBStreamViewType>;

export const awsDynamoDbEventNameExamples = {
  insert: "INSERT",
  modify: "MODIFY",
  remove: "REMOVE",
} as const satisfies Record<string, AWSDynamoDBEventName>;

const modifyRecord = {
  Keys: { id: { S: "user#42" } },
  NewImage: {
    id: { S: "user#42" },
    status: { S: "active" },
  },
  OldImage: {
    id: { S: "user#42" },
    status: { S: "pending" },
  },
  SequenceNumber: "111",
  SizeBytes: 82,
  StreamViewType: "NEW_AND_OLD_IMAGES",
} as const satisfies AWSDynamoDBStreamRecord;

export const awsDynamoDbStreamRecordExamples = {
  modify: modifyRecord,
  insert: {
    Keys: { id: { S: "user#43" } },
    NewImage: { id: { S: "user#43" }, status: { S: "pending" } },
    SequenceNumber: "112",
    SizeBytes: 64,
    StreamViewType: "NEW_IMAGE",
  } satisfies AWSDynamoDBStreamRecord,
  remove: {
    Keys: { id: { S: "user#44" } },
    OldImage: { id: { S: "user#44" }, status: { S: "active" } },
    SequenceNumber: "113",
    SizeBytes: 48,
    StreamViewType: "OLD_IMAGE",
  } satisfies AWSDynamoDBStreamRecord,
  keysOnly: {
    Keys: { id: { S: "user#45" }, sort: { N: "1" } },
    SequenceNumber: "114",
    SizeBytes: 24,
    StreamViewType: "KEYS_ONLY",
  } satisfies AWSDynamoDBStreamRecord,
} as const;

const modifyEvent = {
  eventID: "1",
  eventName: "MODIFY",
  eventVersion: "1.1",
  eventSource: "aws:dynamodb",
  awsRegion: "eu-west-1",
  dynamodb: modifyRecord,
} as const satisfies AWSDynamoDBEventRecord;

export const awsDynamoDbEventRecordExamples = {
  modify: modifyEvent,
  insert: {
    ...modifyEvent,
    eventID: "2",
    eventName: "INSERT",
    dynamodb: awsDynamoDbStreamRecordExamples.insert,
  } satisfies AWSDynamoDBEventRecord,
  remove: {
    ...modifyEvent,
    eventID: "3",
    eventName: "REMOVE",
    dynamodb: awsDynamoDbStreamRecordExamples.remove,
  } satisfies AWSDynamoDBEventRecord,
} as const;

export const awsDynamoDbStreamEventExamples = {
  single: { Records: [modifyEvent] } satisfies AWSDynamoDBStreamEvent,
  mixed: {
    Records: [
      awsDynamoDbEventRecordExamples.insert,
      awsDynamoDbEventRecordExamples.modify,
      awsDynamoDbEventRecordExamples.remove,
    ],
  } satisfies AWSDynamoDBStreamEvent,
} as const;
```
