DynamoDBStreamToKinesisRecordEvent: {
    awsRegion: string;
    dynamodb: {
        ApproximateCreationDateTime?: number;
        Keys: Record<string, Record<string, any>>;
        NewImage?: Record<string, any>;
        OldImage?: Record<string, any>;
        SizeBytes: number;
    };
    eventID: string;
    eventName: "INSERT"
    | "MODIFY"
    | "REMOVE";
    eventSource: "aws:dynamodb";
    recordFormat: "application/json";
    tableName: string;
    userIdentity?:
        | null
        | { principalId: "dynamodb.amazonaws.com"; type: "Service" };
}

Zod schema for Amazon DynamoDB Stream event sent to an Amazon Kinesis Stream.

This schema is best used in conjunction with the KinesisEnvelope when you want to work with the DynamoDB stream event coming from an Amazon Kinesis Stream.

By default, we unmarshall the dynamodb.Keys, dynamodb.NewImage, and dynamodb.OldImage fields for you.

If you want to extend the schema and provide your own Zod schema for any of these fields, you can use the DynamoDBMarshalled helper. In that case, we won't unmarshall the other fields.

To extend the schema, you can use the DynamoDBStreamToKinesisRecord child schema and the DynamoDBMarshalled helper together.

Type declaration

  • awsRegion: string
  • dynamodb: {
        ApproximateCreationDateTime?: number;
        Keys: Record<string, Record<string, any>>;
        NewImage?: Record<string, any>;
        OldImage?: Record<string, any>;
        SizeBytes: number;
    }
  • eventID: string
  • eventName: "INSERT" | "MODIFY" | "REMOVE"
  • eventSource: "aws:dynamodb"
  • recordFormat: "application/json"
  • tableName: string
  • OptionaluserIdentity?: null | { principalId: "dynamodb.amazonaws.com"; type: "Service" }
import {
DynamoDBStreamToKinesisRecord,
DynamoDBStreamToKinesisChangeRecord,
} from '@aws-lambda-powertools/parser/schemas/dynamodb';
import { KinesisEnvelope } from '@aws-lambda-powertools/parser/envelopes/dynamodb';
import { DynamoDBMarshalled } from '@aws-lambda-powertools/parser/helpers/dynamodb';

const CustomSchema = DynamoDBStreamToKinesisRecord.extend({
dynamodb: DynamoDBStreamToKinesisChangeRecord.extend({
NewImage: DynamoDBMarshalled(
z.object({
id: z.string(),
attribute: z.number(),
stuff: z.array(z.string()),
})
),
// Add the lines below only if you want these keys to be unmarshalled
Keys: DynamoDBMarshalled(z.unknown()),
OldImage: DynamoDBMarshalled(z.unknown()),
}),
});

type CustomEvent = z.infer<typeof CustomSchema>;