aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
Unable to export instance of DynamoDBDocumentClient across my app
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
~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!~
False alarm.. it's still not working
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!
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.
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.