[英]JavaScript TypeError: Cannot read property 'id' of undefined
[英]TypeError: Cannot read property 'id' of undefined - AWS Lambda
使用AWS Lambda时遇到问题
TypeError:无法在export.handler上读取未定义的属性'id'(/var/task/index.js:19:28)
这是我的代码:
var AWS = require("aws-sdk");
var dynamoDBConfiguration = {
"region" : "us-west-2",
"endpoint" : "dynamodb.us-west-2.amazonaws.com"
};
AWS.config.update(dynamoDBConfiguration);
var docClient = new AWS.DynamoDB.DocumentClient();
exports.handler = function(event, context, callback) {
var params = {
TableName: "User",
ProjectionExpression: "id, password",
FilterExpression: "id = :id and password = :password",
ExpressionAttributeValues: {
":id" : event.body.id,
":password" : event.body.password
}
};
docClient.scan(params, onScan);
function onScan(err, data) {
if (err) {
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2));
}
else
{
console.log("Scan succeeded.");
context.succeed(data.Items);
// continue scanning if we have more movies
if (typeof data.LastEvaluatedKey != "undefined") {
console.log("Scanning for more...");
params.ExclusiveStartKey = data.LastEvaluatedKey;
docClient.scan(params, onScan);
}
}
}
}
但是,今天下午,当我运行它时,它运行得非常完美。
你们可以帮我解决此错误吗?
提前致谢
FilterExpression:"#id = :id and #password = :password",
ExpressionAttributeNames: {
"#id":"Your particular id",
"#password":"your password"
},
您也可以在代码的参数中使用ExpressionAttributesNames。 我认为可能是您仅使用ExpressionAttributesValues。
这意味着event.body.id是未定义的。 使用event.id代替event.body.id。
难道不是这样吗?
ExpressionAttributeValues: {
":id" : event.id,
":password" : event.password
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.