aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.01k stars 565 forks source link

Unmarshing DynamoStream events #2634

Open maxm450 opened 3 years ago

maxm450 commented 3 years ago

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/util-dynamodb@3.23.0

Steps to reproduce

import { DynamoDBStreamEvent } from 'aws-lambda'
import { unmarshall } from "@aws-sdk/util-dynamodb"

export const handler =  async (event) => {
  for (const record of event.Records) {
    if (record.dynamodb?.NewImage) {
      const streamItem = record.dynamodb?.NewImage
      const item = unmarshall(streamItem)
      console.log(item)
    }
  }
}

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

monken commented 3 years ago

unmarshall will also not convert binary attributes properly. The DynamoDB stream will provide a base64 encoded presentation of the binary attribute and unmarshall does not base64-decode the value.

sekhavati commented 2 years ago

I'm still seeing this issue in 3.34.0.

Interestingly there are no type errors if my package only contains @aws-sdk/util-dynamodb. But as soon as I install @aws-sdk/client-dynamodb the aforementioned TypeScript errors pop up.

From my brief testing with unmarshall it behaved as expected prior to installing @aws-sdk/client-dynamodb , so as a workaround I've set a @ts-ignore on the problematic line of code for now.

ajredniwja commented 2 years ago

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 unmarshall correctly used: https://www.npmjs.com/package/@aws-sdk/lib-dynamodb.

alFReD-NSH commented 1 year ago

Yes, this is still an issue as the types are not compatible. More info about it in DefinitelyTyped/DefinitelyTyped#51331

nikiitat commented 9 months ago

Any updates on this one? I think this is also related to: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/51331

obones commented 3 months ago

unmarshall will also not convert binary attributes properly. The DynamoDB stream will provide a base64 encoded presentation of the binary attribute and unmarshall does not base64-decode the value.

I'm facing the same behavior here and I'm not sure what to do here. Should this be reported in a separate issue?