aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
MIGRATION ISSUE: Undocumented change in the behaviour of DynamoDB marshalling
Pre-Migration Checklist
- [X] I've read the Migration Guide.
- [X] I've reviewed the upgrading notes and major version differences mentioned in
UPGRADING.md
. - [X] I've checked AWS Forums and StackOverflow for similar migration issues.
Which JavaScript Runtime is this issue in?
Node.js (includes AWS Lambda)
AWS Lambda Usage
- [X] Yes, my application is running on AWS Lambda.
- [X] No, my application is not running on AWS Lambda.
Describe the Migration Issue
It appears that version 2 automatically omitted undefined values. To restore this "feature" in version 3, the removeUndefinedValues
option must be set. I did not find this mentioned in the migration guide or notes.
Code Comparison
import { DynamoDB } from 'aws-sdk';
import { marshall } from '@aws-sdk/util-dynamodb';
const sample = {
foo: 'test',
bar: undefined,
};
console.log('sample', sample);
const marshalledV2 = DynamoDB.Converter.marshall(sample);
console.log('marshalledV2', marshalledV2);
const marshalledV3 = marshall(sample, { removeUndefinedValues:true });
console.log('marshalledV3', marshalledV3);
Observed Differences/Errors
-
removeUndefinedValues
option not set:
❯ pnpm ts-node asd.ts
sample { foo: 'test', bar: undefined }
marshalledV2 { foo: { S: 'test' } }
~/.../@aws-sdk/util-dynamodb/dist-cjs/index.js:99
throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
...
-
removeUndefinedValues
set totrue
:
❯ pnpm ts-node asd.ts
sample { foo: 'test', bar: undefined }
marshalledV2 { foo: { S: 'test' } }
marshalledV3 { foo: { S: 'test' } }
Additional Context
https://github.com/aws/aws-sdk-js-v3/issues/1816 https://github.com/aws/aws-sdk-js-v3/pull/1840
Hi @andrejleitner ,
Thanks for bringing this up. We will add it to the migration guide.
All the best, Ran~
So here is the solution: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#undefined-values-in-when-marshalling
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.