-
Notifications
You must be signed in to change notification settings - Fork 589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unmarshing DynamoStream events #2634
Comments
|
I'm still seeing this issue in Interestingly there are no type errors if my package only contains From my brief testing with |
Hey everyone, apologies the issue fell out of queue. A lot of changes and features were added to the latest package. Is it still an persisting issue with the latest version. I was able to use |
Yes, this is still an issue as the types are not compatible. More info about it in DefinitelyTyped/DefinitelyTyped#51331 |
Any updates on this one? |
I'm facing the same behavior here and I'm not sure what to do here. |
Any update on this? I'm facing the same issue with the latest version |
Hey everyone, I want to provide this workaround so you can decode the binary attributes. import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { unmarshall } from "@aws-sdk/util-dynamodb";
const dynamoClient = new DynamoDBClient({ region: "us-west-2" });
function customUnmarshall(item) {
const unmarshalled = unmarshall(item);
for (const [key, value] of Object.entries(unmarshalled)) {
if (item[key] && item[key].B) {
// Decode the base64 string to a UTF-8 string
unmarshalled[key] = Buffer.from(item[key].B, 'base64').toString('utf-8');
}
}
return unmarshalled;
}
export const handler = async (event) => {
for (const record of event.Records) {
if (record.dynamodb?.NewImage) {
const streamItem = record.dynamodb.NewImage;
const item = customUnmarshall(streamItem);
console.log("Unmarshalled item (including decoded binary attributes):", item);
for (const [key, value] of Object.entries(item)) {
if (typeof value === 'string' && item[key] && item[key].B) {
console.log(`Decoded binary attribute ${key}:`, value);
}
}
}
}
}; |
Using the workaround above, I used the following test case of DynamoDB object and it's working : {
"Records": [
{
"eventID": "1",
"eventName": "INSERT",
"eventVersion": "1.0",
"eventSource": "aws:dynamodb",
"awsRegion": "us-west-2",
"dynamodb": {
"Keys": {
"Id": {
"N": "101"
}
},
"NewImage": {
"Id": {
"N": "101"
},
"Name": {
"S": "John Doe"
},
"BinaryData": {
"B": "SGVsbG8gV29ybGQ="
}
},
"SequenceNumber": "111",
"SizeBytes": 26,
"StreamViewType": "NEW_AND_OLD_IMAGES"
},
"eventSourceARN": "arn:aws:dynamodb:us-west-2:123456789012:table/YourTableName/stream/2023-05-11T00:00:00.000"
},
{
"eventID": "2",
"eventName": "MODIFY",
"eventVersion": "1.0",
"eventSource": "aws:dynamodb",
"awsRegion": "us-west-2",
"dynamodb": {
"Keys": {
"Id": {
"N": "102"
}
},
"NewImage": {
"Id": {
"N": "102"
},
"Name": {
"S": "Jane Smith"
},
"BinaryData": {
"B": "SGVsbG8gQWdhaW4="
}
},
"SequenceNumber": "222",
"SizeBytes": 28,
"StreamViewType": "NEW_AND_OLD_IMAGES"
},
"eventSourceARN": "arn:aws:dynamodb:us-west-2:123456789012:table/YourTableName/stream/2023-05-11T00:00:00.000"
}
]
} This is the log I got "
@jimmyn, Thanks! |
Just talked with the team, it seems the issue is caused by the type mismatch. Please vote or reply if you are encountering this issue with aws-lambda pkg installed |
Yes, this is exactly what happens. |
Describe the bug
TS types seems to cause an issue when unmarshing a dynamoStream
Argument of type '{ [key: string]: AWSLambda.AttributeValue; }' is not assignable to parameter of type '{ [key: string]: import("/node_modules/@aws-sdk/client-dynamodb/dist/types/models/models_0").AttributeValue; }'.
Your environment
SDK version number
@aws-sdk/[email protected]
Steps to reproduce
Observed behavior
receiving typing issue for AttributeValue type.
Expected behavior
should be able to unmarshall a Dynamo object, wherever the object comes from a stream event or a getItem action from the DynamoClient
The text was updated successfully, but these errors were encountered: