我正在尝试从DynamoDB上的AWS API Gateway读取单行。
数据库结构如下:
好的,我已经设置了映射模板,如下所示:
最后是我的Lambda代码:
console.log('function starts');
const AWS = require('aws-sdk');
const docClient = new AWS.DynamoDB.DocumentClient({region: 'us-east-2'});
exports.handler = function(event, context, callback){
console.log('processing event: %j', event);
let scanningParameters = {
TableName: 'users',
Key: {
"userid": event.userid
},
Limit: 1 //maximum result of 1 items
};
//In dynamoDB scan looks through your entire table and fetches all data
docClient.get(scanningParameters, function(err,data){
if(err){
callback(err, null);
}else{
callback(null,data);
}
});
}
测试时间
但是,使用CURL测试我的进度会返回:
curl -X GET \
mysite\
-H 'Content-Type: application/json' \
-d '{
“userid”: “some user id”
}'
但是得到:
{“ errorMessage”:“一个或多个参数值无效:AttributeValue可能不包含空字符串”,“ errorType”:“ ValidationException”,“ stackTrace”:[“ Request.extractError(/ var / runtime / node_modules / aws-sdk / lib / protocol / json.js:48:27)“,” Request.callListeners(/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:105:20)“,”请求.emit(/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:77:10)","Request.emit(/var/runtime/node_modules/aws-sdk/lib/request.js:683: 14)“,” Request.transition(/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)","AcceptorStateMachine.runTo(/ var / runtime / node_modules / aws-sdk / lib / state_machine.js:14:12)“,” /“ var / runtime / node_modules / aws-sdk / lib / state_machine.js:26:10”,“请求。(/ var / runtime / node_modules / aws-sdk / lib / request.js:38:9)“,”请求。(/var/runtime/node_modules/aws-sdk/lib/request.js:685:12)","Request.callListeners(/ var / runtime / node_modules / aws -sdk / lib / sequential_executor.js:115:18)“]}