aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Unable to export instance of DynamoDBDocumentClient across my app

Open bneigher opened this issue 3 years ago • 2 comments

Describe the bug

Typically - I like to instantiate instances of my aws sdk resource clients in an area in my source code, like utils, where I can import that instance and fire away (with any parameters needed when creating the instance passed in in that one place).

However - I'm noticing that with the following example, those options are not persisting on the instance export..

Expected Behavior

I am expecting the dynamoDocumentClient instance that I have booted with my parameters to be exported as expected with my translationConfig options, but it appears that that is not persisted... is this intentional behavior? Am I instantiating this correctly? When I log the config options in the utils file where I export it - it shows the correct options loaded into the instance...

Current Behavior

{
  marshallOptions: {
    convertEmptyValues: false,
    removeUndefinedValues: false,
    convertClassInstanceToMap: false
  },
  unmarshallOptions: { wrapNumbers: false }
}

Reproduction Steps

In a file called src/utils/dynamo.ts

import { DynamoDBClient } from '@aws-sdk/client-dynamodb'
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb'

const config = {
  region: process.env.AWS_REGION,
  accessKeyId: process.env.AWS_ACCESS_KEY_ID,
  secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
  sessionToken: process.env.AWS_SESSION_TOKEN
}

const marshallOptions = {
  // Whether to automatically convert empty strings, blobs, and sets to `null`.
  convertEmptyValues: true, // false, by default.
  // Whether to remove undefined values while marshalling.
  removeUndefinedValues: true, // false, by default.
  // Whether to convert typeof object to map attribute.
  convertClassInstanceToMap: true // false, by default.
}

const unmarshallOptions = {
  // Whether to return numbers as a string instead of converting them to native JavaScript numbers.
  wrapNumbers: false // false, by default.
}

const translateConfig = { marshallOptions, unmarshallOptions }

export const dynamoClient = new DynamoDBClient(config)
export const dynamoDocumentClient = DynamoDBDocumentClient.from(dynamoClient, translateConfig)

somewhere in my service in a file src/index.ts

import { dynamoDocumentClient  } from 'utils/dynamodb'

const run = () => {
  console.log(dynamoDocumentClient.config.translateConfig)
 /* outputs 
 *   {
 *     marshallOptions: {
 *       convertEmptyValues: false,
 *        removeUndefinedValues: false,
 *        convertClassInstanceToMap: false
 *      },
 *     unmarshallOptions: { wrapNumbers: false }
 *   }
 */
}

Possible Solution

No response

Additional Information/Context

No response

SDK version used

"@aws-sdk/client-dynamodb": "^3.131.0"

Environment details (OS name and version, etc.)

Mac OS Monterey, 12.4, M1 Macbook Pro

bneigher avatar Jul 26 '22 06:07 bneigher

~Hey team - has this been addressed? I've updated @aws-sdk/client-dynamodb since, and it appears that it is now persisting the config values in my instance. However - I would like to validate that there was an issue before, so that I can trust this updated version into PROD. Thanks!~

bneigher avatar Aug 08 '22 20:08 bneigher

False alarm.. it's still not working

bneigher avatar Aug 08 '22 21:08 bneigher

Hi @bneigher, thanks for opening this issue. I just did a test in my local environment and everything is working fine. Could you please check if anywhere else this setting is being altered for the client?, could you please maybe just do a test in an clean project just using those two files and see if you get the same behavior?

Thanks!

yenfryherrerafeliz avatar Jan 17 '23 07:01 yenfryherrerafeliz

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

github-actions[bot] avatar Jan 25 '23 00:01 github-actions[bot]

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Feb 13 '23 00:02 github-actions[bot]