当键匹配时,我想从dynamodb返回数据


**I want to return the data key values but it is not working. Please help me. The main concept of this method is when this is invoke dal is the keyword and it fetches that key values from the dynamodb. For that i used global also but not updating that global variable also.

我试着从回调中返回值,并将结果分配给函数内的一个局部变量并返回该变量,但这些方法都没有实际返回响应(它们都返回未定义的或变量结果的初始值(。**

function getLocation(){
let a=[];
const documentClient = new AWSS.DynamoDB.DocumentClient({region:"us-east-2"});
const params = {
TableName : "ProductLocation1",
Key :{
Product_Name : 'dal'
}
};
documentClient.get(params,(err,data)=>{
if(err){
console.log('error is',err);
}
console.log('data is : ',data);
global.a=Object.keys(data);
});
return global.a;
}
try {
const result = await documentClient.get(params).promise();
} catch (error) {
// handle error
}

你可以使用promise&wait而不是回调函数。通过这种方式,您不需要将它们存储在局部变量中。

最新更新