I'm trying to scan the table and show only few data which equals to cognitoUserName. Basically the table contains multiple user data. I need to show data of only the logged in user. Like user specific data. So I have used field userName in which the email id which is unique of the user will be added into dynamodb table. And that userName is sortkey.
#My handler Function
Partition Key is **certificateId** is unique.
Sort Key is userName will be same for some.
module.exports.getAllCertificate = async (event, context, cb) => {
context.callBackWaitsForEmptyEventLoop = false;
let data = JSON.parse(event.body);
cognitoUserName= data.email;
try{
var params = {
TableName: CERTIFICATE_TABLE_NAME,
FilterExpression: "userName = :userName",
ExpressionAttributeValues:{
":userName": cognitoUserName
}
};
const certiificates = await documentClient.scan(params).promise()
console.log(JSON.stringify(certiificates));
cb(null,send(200, certiificates));
} catch(err){
cb(null,send(500,err.message));
}
};
error: {message: 'Internal server error'}
headers: HttpHeaders "Http failure response for https://duth-1.amazonaws.com/dev/certificateList: 502 OK"
name: "HttpErrorResponse"
ok: false
status: 502
statusText:"OK"
url: "https://uth-1.amazonaws.com/dev/certificateList"