From 4e9d905d078ab5828921899f345dbcf0e9a807bd Mon Sep 17 00:00:00 2001 From: RanVaknin Date: Thu, 25 Jan 2024 02:19:03 +0000 Subject: [PATCH 1/3] docs(main): adding info about remove undefined values for doc client marshalling --- UPGRADING.md | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index f27f88046728..7606a1985467 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -458,13 +458,17 @@ S3 client in v3 supports S3 global client, or following region redirects, if an ## DynamoDB Document Client -In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) -to call DynamoDB API with native JavaScript types like Buffer, Array, and Object. It thus simplifies working with items -in Amazon DynamoDB by abstracting away the notion of attribute values. +### Basic Usage of DynamoDB Document Client in v3 -In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html) -is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB -client in its constructor. Here's an brief example: +- In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) + to call DynamoDB API with native JavaScript types like Buffer, Array, and Object. It thus simplifies working with items + in Amazon DynamoDB by abstracting away the notion of attribute values. + +- In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html) + is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB + client in its constructor. + +Example: ```javascript import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; // ES6 import @@ -489,6 +493,39 @@ await ddbDocClient.send( ); ``` +### Undefined Values in Marshalling + +- In v2 `undefined` values in objects were automatically omitted during the marshalling process to DynamoDB. + +- In v3, using [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html), the default behavior has changed: `undefined` values in objects are now included during marshalling. Developers need to explicitly manage undefined values to exclude them using the `removeUndefinedValues` flag. + +Example: + +```js +import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; +import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; +import { marshall } from "@aws-sdk/util-dynamodb"; + +const client = new DynamoDBClient({}); + +const ddbDocClient = DynamoDBDocumentClient.from(client); + +const item = { + id: "123", + content: undefined, +}; + +const marshalledItem = marshall(item, { removeUndefinedValues: true }); + +// procceed with making the API call as usual: +await ddbDocClient.send( + new PutCommand({ + TableName: "YourTableName", + Item: marshalledItem, + }) +); +``` + More examples and configurations are available in the [package README](https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-dynamodb/README.md). ## Waiters From af2d935c8a53291c929cd54d24f226020c237ab0 Mon Sep 17 00:00:00 2001 From: RanVaknin Date: Tue, 30 Jan 2024 22:17:42 +0000 Subject: [PATCH 2/3] docs(main): fixing code example to not use marshall function --- UPGRADING.md | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 7606a1985467..1e8f49276583 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -493,35 +493,34 @@ await ddbDocClient.send( ); ``` -### Undefined Values in Marshalling +### `undefined` values in when marshalling - In v2 `undefined` values in objects were automatically omitted during the marshalling process to DynamoDB. -- In v3, using [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html), the default behavior has changed: `undefined` values in objects are now included during marshalling. Developers need to explicitly manage undefined values to exclude them using the `removeUndefinedValues` flag. +- In v3, the default marshalling behavior in @aws-sdk/lib-dynamodb has changed: objects with `undefined` values are no longer omitted. To align with v2's functionality, developers must explicitly set the `removeUndefinedValues` to `true` in the `marshallOptions` of the DynamoDBDocumentClient. Example: ```js import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb"; -import { marshall } from "@aws-sdk/util-dynamodb"; const client = new DynamoDBClient({}); -const ddbDocClient = DynamoDBDocumentClient.from(client); +// The DynamoDBDocumentClient is configured to handle undefined values properly +const ddbDocClient = DynamoDBDocumentClient.from(client, { + marshallOptions: { + removeUndefinedValues: true + } +}); -const item = { - id: "123", - content: undefined, -}; - -const marshalledItem = marshall(item, { removeUndefinedValues: true }); - -// procceed with making the API call as usual: await ddbDocClient.send( new PutCommand({ - TableName: "YourTableName", - Item: marshalledItem, + TableName, + Item: { + id: "123", + content: undefined // This value will be automatically omitted + }; }) ); ``` From 912c4ad11d2cfee198c74106a973b765c8212a44 Mon Sep 17 00:00:00 2001 From: RanVaknin Date: Tue, 30 Jan 2024 22:46:09 +0000 Subject: [PATCH 3/3] docs(main): fixing description for basic use section --- UPGRADING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 1e8f49276583..b3a3e6855746 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -461,10 +461,10 @@ S3 client in v3 supports S3 global client, or following region redirects, if an ### Basic Usage of DynamoDB Document Client in v3 - In v2, you can use the [`AWS.DynamoDB.DocumentClient` class](https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html) - to call DynamoDB API with native JavaScript types like Buffer, Array, and Object. It thus simplifies working with items + to call DynamoDB API with native JavaScript types like Array, Number, and Object. It thus simplifies working with items in Amazon DynamoDB by abstracting away the notion of attribute values. -- In v3, equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html) +- In v3, the equivalent [`@aws-sdk/lib-dynamodb`](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/modules/_aws_sdk_lib_dynamodb.html) is available. It's similar to normal service clients from v3 SDK, with the difference that it takes a basic DynamoDB client in its constructor.