Connected to dynamoDb table using Nodejs, I want to fetch items from table. I tried using query option, it returns json with items but some times it returns Json with syntax error
This is my code:
let ddb = new AWS.DynamoDB(config)
export const dynamoDb = ddb
export const dynamoClient = new AWS.DynamoDB.DocumentClient({
service: dynamoDb
})
let params = {
TableName: auditTable,
IndexName: 'importId-auditStatus-index',
KeyConditionExpression: 'importId = :importId and auditStatus = :auditStatus',
ExpressionAttributeValues: {
':importId': importId,
':auditStatus' : 'Imported'
}
}
let response = await dynamoClient.query(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
return data;
}
}).promise();
console.log("response",response)
Some times it returns Json with syntax error as given below
{
"Count":117,
"Items":[
... truncated by me ...
{
"pricingTemplate":{
"NULL":true
},
"auditId":{
"S":"7555555_15287101"
},
"importId":{
"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"
},
"auditStatus":{
"S":"Imported"
},
"Id":{
"S":"420f50cb-3d03-49cb-b1da-1a36aa099e6c"
},
"recordType":{
"S":"currecy_test_tl"
}
}
,{"pricingTemplate":{"NULL":true},"auditId":{"S":"7555555_15287164"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"}7555555_15287206"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"},"Id":{"S":"e7042719-fa77-4939-9d05-ad41f3bdc7dc"},"recordType":{"S":"currecy_test_tl"}},{"pricingTemplate":{"NULL":true},"auditId":{"S":"7555555_15287155"},"importId":{"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"},"auditStatus":{"S":"Imported"},"Id":{"S":"bee5d2e3-60cf-4ecf-8249-d25de6e8c28a"},"recordType":{"S":"currecy_test_tl"}},
{
"pricingTemplate":{
"NULL":true
},
"auditId":{
"S":"7555555_15287111"
},
"importId":{
"S":"8c6976bb-8680-47ce-bcfb-470c8e97740f"
},
"auditStatus":{
"S":"Imported"
},
"Id":{
"S":"2161a17f-63c5-4c45-b7b4-9750cc202b23"
},
"recordType":{
"S":"currecy_test_tl"
}
}
],
"ScannedCount":117
}
Edit:
Syntax error at
auditStatus":{"S":"Imported"}7555555_15287206"},
The code you're sharing and the output you shared are not aligned. The Document Client dynamoClient
which you use in the code returns native JSON. The low level client dynamoDb
and ddb
in your code will return DynamoDB JSON, which is what you are outputting and calling a syntax error.