aws-lambda - DynamoDB query shows UnepectedParameter
问题描述
I'm trying to create a query in Lambda for a DynamoDB table.
I have followed the Instructions and examples from the aws developer handbook but still get an error
//+++++++++++++++++++++++++++++++++++++++++++
//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);
}
});
};
The database is populated and should provide some results.
However Lambda throws the following error: "errorMessage": "There were 14 validation errors:\n* InvalidParameterType: Expected params.ExpressionAttributeValues[':a'] to be a structure"
Could you please tell me what to change to make the query work?
解决方案
您需要使用DynamoDB Document Client或将 ExpresionAttributeValue 更改为
ExpressionAttributeValues: {
":a": {
"S": "9783453471092"
}
}
推荐阅读
- docker-compose - docker-compose 中的网络可见性
- azure - Azure Wep 应用连接外部 Cloud SQL
- java - 通过比较存储为字符串列表的边值来显示三角形
- php - Oracle 数据库未使用 PHP 正确排序日期
- signalr - 如何使用 Angular 7 获取特定页面中的总活跃用户数
- php - 如何计算具有不同记录的查询?
- reporting-services - 我能否从我的自定义实用程序创建 Tableau(或任何其他报告工具)可以读取的报告文件?
- docker - 无法安装 Docker:Docker 桌面需要 Windows 10 专业版或企业版 15063 才能运行
- amp-html - AMP页面如果你使用浏览器返回,你不能点击任何其他链接
- javascript - 背包问题还是排列?如何解决我的问题?