I'm migrating a project with the V3 sdk of AWS for DynamoDB on NodeJS.
In V2 there was no problem retrieving data during the PUT operation with the DocumentClient API. The method returns the item inserted without any problem.
I'm not sure why the V3 putCommand doesn't do the same. The operation happens as expected and I can see the item inserted in my DB but I don't know if it is possible to return the inserted item.
I've spent hours reading the aws docs but I can't find the solution. I have to say that the AWS docs are not pretty clear from my opinion
Here is an example of my code:
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const { DynamoDBDocumentClient, PutCommand } = require('@aws-sdk/lib-dynamodb');
async writeItemHelper(tableName, item) {
const marshallOptions = {
convertEmptyValues: true,
convertClassInstanceToMap: true
}
this.rawClient = new DynamoDBClient({ region: process.env.AWS_REGION })
this.client = DynamoDBDocumentClient.from(this.rawClient, { marshallOptions })
try {
const command = new PutCommand({ TableName: tableName, Item: item} )
const cmdResult = await this.client.send(command)
return cmdResult;
} catch (err) {
console.error(`DynDB::writeItem ${JSON.stringify(err)}`);
throw {error: err};
}
And here is the response:
{
"$metadata": {
"httpStatusCode": 200,
"requestId": "698LOHMFMO7NHPC1TG7MLRVE7VVV4KQNSO5AEMVJF66Q9ASUAAJG",
"attempts": 1,
"totalRetryDelay": 0
},
"Attributes": undefined,
"ConsumendCapacity": undefined,
"ItemCollectionMetrics": undefined
}
As you can see the operation works as expected but there is no any info about the item inserted. Do you know if there is any config that I'm missing?
Thank you so much J.
item
instead ofcmdResult
.