When I receive an dynamodb stream event in typescript, I see below schema:
Records: [
{
eventID: '78dfd1ba7a17adde3cbc987e5af92f91',
eventName: 'INSERT',
eventVersion: '1.1',
eventSource: 'aws:dynamodb',
awsRegion: 'ap-southeast-2',
dynamodb: [
{
"id": {
"S": "xxx"
},
"type": {
"S": "xxx"
}
},
"NewImage": {
...
},
"OldImage": { ... }
],
eventSourceARN: 'arn:aws:dynamodb:ap-southeast-2:115136697128:table/joeyDevices/stream/2020-07-10T04:42:54.695'
}
]
Is there a type definition I can use for this event in typescript?
Is there a type definition I can use for this event in typescript?
If you are using an AWS Lambda to process dynamo stream events, you can find type definitions in the @types/aws-lambda package.
import { DynamoDBStreamEvent } from "aws-lambda";
You can see the full type definition here in the github repo for @types/aws-lambda.
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_StreamRecord.html
export interface StreamRecord {
ApproximateCreationDateTime?: number;
Keys?: { [key: string]: AttributeValue };
NewImage?: { [key: string]: AttributeValue };
OldImage?: { [key: string]: AttributeValue };
SequenceNumber?: string;
SizeBytes?: number;
StreamViewType?: 'KEYS_ONLY' | 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES';
}
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_Record.html
export interface DynamoDBRecord {
awsRegion?: string;
dynamodb?: StreamRecord;
eventID?: string;
eventName?: 'INSERT' | 'MODIFY' | 'REMOVE';
eventSource?: string;
eventSourceARN?: string;
eventVersion?: string;
userIdentity?: any;
}
// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-ddb-update
export interface DynamoDBStreamEvent {
Records: DynamoDBRecord[];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With