我正在尝试在 Lambda中为DynamoDB表创建查询。
我遵循了aws开发人员手册中的说明和示例,但仍然出现错误
//+++++++++++++++++++++++++++++++++++++++++++
//The database Structure
"Table": {
"AttributeDefinitions": [
{
"AttributeName": "Score",
"AttributeType": "N"
},
{
"AttributeName": "gtin_RecBook",
"AttributeType": "S"
},
{
"AttributeName": "gtin_RefBook",
"AttributeType": "S"
}
],
"TableName": "Recommendation_test_2",
"KeySchema": [
{
"AttributeName": "gtin_RefBook",
"KeyType": "HASH"
},
{
"AttributeName": "gtin_RecBook",
"KeyType": "RANGE"
}
]
}
//+++++++++++++++++++++++++++++++++++++++++++
// The Lambda Code
const AWS = require('aws-sdk');
const dynamodb = new AWS.DynamoDB({region:'eu-central-1', apiVersion:'2012-08-10'});
exports.handler = (event, context, callback) => {
const params = {
TableName: "Recommendation_test_2",
KeyConditionExpression: "gtin_RefBook = :a",
ExpressionAttributeValues: {
":a": "9783453471092"
}
};
dynamodb.query(params, function(err, data){
if (err) {
console.log(err);
callback(err);
} else{
console.log(data);
callback(null, data);
}
});
};
该数据库已填充,应该会提供一些结果。
但是Lambda会引发以下错误: “ errorMessage”:“存在14个验证错误:\ n * InvalidParameterType:预期的params.ExpressionAttributeValues [':a']为结构”
能否请您告诉我要进行哪些更改以使查询正常工作?
答案 0 :(得分:0)
您需要使用DynamoDB Document Client或将ExpresionAttributeValue更改为
ExpressionAttributeValues: {
":a": {
"S": "9783453471092"
}
}