Zha*_* Yi 2 amazon-dynamodb typescript
当我在打字稿中收到 dynamodb 流事件时,我看到以下架构:
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'
}
]
Run Code Online (Sandbox Code Playgroud)
在打字稿中是否有我可以用于此事件的类型定义?
小智 6
在打字稿中是否有我可以用于此事件的类型定义?
如果您使用 AWS Lambda 来处理 dynamo 流事件,您可以在@types/aws-lambda包中找到类型定义。
import { DynamoDBStreamEvent } from "aws-lambda";
Run Code Online (Sandbox Code Playgroud)
您可以在@types/aws-lambda的 github 存储库中查看完整的类型定义。
// 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[];
}
Run Code Online (Sandbox Code Playgroud)
只是对已接受答案的补充
// http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_streams_StreamRecord.html
export interface StreamRecord<T> {
ApproximateCreationDateTime?: number;
Keys?: { [key: string]: AttributeValue };
NewImage?: T;
OldImage?: T;
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<T> {
awsRegion?: string;
dynamodb?: StreamRecord<T>;
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<T> {
Records: DynamoDBRecord<T>[];
}
Run Code Online (Sandbox Code Playgroud)
如果您在自己的项目中实现,则应该使用您自己的类型扩展它。
| 归档时间: |
|
| 查看次数: |
979 次 |
| 最近记录: |