AWS.DynamoDB.DocumentClient不提供put的数据

我正在使用AWS.DynamoDB.DocumentClient和Dynamodb local(端口8080)。 当我执行put时,callback中的datavariables是一个空对象。 我错过了什么吗?

 import * as AWS from "aws-sdk"; AWS.config.update({ region: "us-west-2", endpoint: "http://localhost:8080" }); const docClient: any = new AWS.DynamoDB.DocumentClient(); const item = { someField: "456", other: "123" }; const params = { TableName: "TableName", Item: item }; docClient.put(params, function(err, data) { if (err) console.log(err); else console.log(data); // this produces: {} }); 

没有错误,并且正在插入项目\更新 – 但是datavariables是一个空的对象。 这不应该包含价值?

谢谢

你并没有要求任何价值观回来,那么为什么你期望有什么价值回来呢? 您需要设置适当的参数ReturnConsumedCapacity和/或ReturnItemCollectionMetrics和/或ReturnValues如果你想要的任何回来的响应。

由于您无法为实际返回有用的“ReturnValues”设置值,因此我通过简单地传回传入的原始项目数据来解决此问题。

 import * as AWS from "aws-sdk"; AWS.config.update({ region: "us-west-2", endpoint: "http://localhost:8080" }); const docClient: any = new AWS.DynamoDB.DocumentClient(); const item = { someField: "456", other: "123" }; const params = { TableName: "TableName", Item: item }; // Have a clear reference to this scope var self = this; docClient.put(params, function(err, data) { if (err) console.log(err); else console.log(self.params.Item); // this should return the data you passed in! }); 

我把“自我”设置为“这个”,以清楚我在从哪里读取数据。 希望帮助别人!