AWS.DynamoDB.DocumentClient不提供put的数据
我正在使用AWS.DynamoDB.DocumentClient和Dynamodb local(端口8080)。 当我执行put时,callback中的data
variables是一个空对象。 我错过了什么吗?
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: {} });
没有错误,并且正在插入项目\更新 – 但是data
variables是一个空的对象。 这不应该包含价值?
谢谢
你并没有要求任何价值观回来,那么为什么你期望有什么价值回来呢? 您需要设置适当的参数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! });
我把“自我”设置为“这个”,以清楚我在从哪里读取数据。 希望帮助别人!
- DynamoDB putitem在NodeJs中 – 对象数组
- 你如何unit testing一个NodeJs的Lambda函数写入/读取dynamodb,并通过AWS API网关端点调用?
- AWS DynamoDB问题:用户无权在资源上执行:dynamodb:PutItem
- 不能更新Dynamo Db表,得到ValidationException
- 在Dynamo dB的获取操作中,“在参数中缺less必需的键”键
- 如何使用DynamoDB批量删除?
- 使用node.js更新expression式上的发电机数据库错误
- 通过JavaScript访问Amazon DynamoDB上的数据
- Nodejs错误:读取ECONNRESET