dynamodb.put().promise() not returning the put object(dynamodb.put().promise() 不返回 put 对象)
问题描述
我正在尝试使用 async/await 与 aws 和 dynamo db 相关的功能.下面是一个如何在异步等待之前放置对象的示例,正如您在回调中看到的那样,您可以访问包含放置对象的数据.然而,在使用 async 和 promise 的第二个代码块中,结果是一个空对象,有什么想法吗?
I am trying to make use of the async/await functionality with regard to aws and dynamo db. Below is an example of how to put an object pre asyn await, as you can see in the callback you have access to data which contains the put object. However in the second block of code which uses async and promise the result is an empty object, any thoughts?
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.03.html
非承诺版本
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "Movies";
var year = 2015;
var title = "VGhlIEJpZyBOZXcgTW92aWU=";
var params = {
TableName:table,
Item:{
"year": year,
"title": title,
"info":{
"plot": "Nothing happens at all.",
"rating": 0
}
}
};
console.log("Adding a new item...");
docClient.put(params, function(err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("Added item:", JSON.stringify(data, null, 2));
}
});
Promise async 版本 - 假设包装函数被标记为异步
var docClient = new AWS.DynamoDB.DocumentClient();
var table = "Movies";
var year = 2015;
var title = "VGhlIEJpZyBOZXcgTW92aWU=";
var params = {
TableName:table,
Item:{
"year": year,
"title": title,
"info":{
"plot": "Nothing happens at all.",
"rating": 0
}
}
};
const result: any = await dynamoDb.put(params).promise()
console.log(result)
推荐答案
根据doc 如果你想要返回一些东西,你必须使用 ReturnValues
.
According to the doc you have to use ReturnValues
if you want something back.
这篇关于dynamodb.put().promise() 不返回 put 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:dynamodb.put().promise() 不返回 put 对象


- Flexslider 箭头未正确显示 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Fetch API 如何获取响应体? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01