I am trying to unmarshal a dynamodb stream record with help of the official unmarshall
function available in @aws-sdk/util-dynamodb
.
I am doing this in typescript and the definition looks like this
unmarshall: (data: Record<string, AttributeValue>, options?: unmarshallOptions | undefined)
Here AttributValue
is derived from @aws-sdk/client-dynamodb
.
The incoming type of dynamodb record looks like this
export interface DynamoDBRecord {
awsRegion?: string | undefined;
dynamodb?: StreamRecord | undefined;
eventID?: string | undefined;
eventName?: 'INSERT' | 'MODIFY' | 'REMOVE' | undefined;
eventSource?: string | undefined;
eventSourceARN?: string | undefined;
eventVersion?: string | undefined;
userIdentity?: any;
}
export interface StreamRecord {
ApproximateCreationDateTime?: number | undefined;
Keys?: { [key: string]: AttributeValue } | undefined;
NewImage?: { [key: string]: AttributeValue } | undefined;
OldImage?: { [key: string]: AttributeValue } | undefined;
SequenceNumber?: string | undefined;
SizeBytes?: number | undefined;
StreamViewType?: 'KEYS_ONLY' | 'NEW_IMAGE' | 'OLD_IMAGE' | 'NEW_AND_OLD_IMAGES' | undefined;
}
export interface AttributeValue {
B?: string | undefined;
BS?: string[] | undefined;
BOOL?: boolean | undefined;
L?: AttributeValue[] | undefined;
M?: { [id: string]: AttributeValue } | undefined;
N?: string | undefined;
NS?: string[] | undefined;
NULL?: boolean | undefined;
S?: string | undefined;
SS?: string[] | undefined;
}
Here Attribute
value is coming from @types/aws-lambda/trigger/dynamodb-stream.d.ts
When I do unmarshall(dynamodbRecord.dynamodb.NewImage)
I am getting the error
Argument of type '{ [key: string]: AttributeValue; }' is not assignable to parameter of type 'Record<string, AttributeValue>'. Index signatures are incompatible. Type 'AWSLambda.AttributeValue' is not assignable to type 'import("/Users/hitesh/learnapp/la-aws/node_modules/@aws-sdk/client-dynamodb/dist-types/models/models_0").AttributeValue'. Property '$unknown' is missing in type 'AttributeValue' but required in type '$UnknownMember'.
Why do we have different definations of AttributeValue
in @aws-sdk/client-dynamodb
and @types/aws-lambda/trigger/dynamodb-stream.d.ts
?