[英]TypeError: Cannot read property 'id' of undefined - AWS Lambda
I got issue when working with AWS Lambda 使用AWS Lambda时遇到问题
TypeError: Cannot read property 'id' of undefined at exports.handler (/var/task/index.js:19:28)
TypeError:无法在export.handler上读取未定义的属性'id'(/var/task/index.js:19:28)
Here is my code: 这是我的代码:
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);
}
}
}
}
However, this afternoon, when I ran it, it ran perfectly. 但是,今天下午,当我运行它时,它运行得非常完美。
Can you guys help me to fix this error? 你们可以帮我解决此错误吗?
Thanks in advance 提前致谢
FilterExpression:"#id = :id and #password = :password",
ExpressionAttributeNames: {
"#id":"Your particular id",
"#password":"your password"
},
You can use the ExpressionAttributesNames also in the params of your code. 您也可以在代码的参数中使用ExpressionAttributesNames。 I think it may be you are using ExpressionAttributesValues only.
我认为可能是您仅使用ExpressionAttributesValues。
It means that event.body.id is undefined. 这意味着event.body.id是未定义的。 Use event.id instead of event.body.id.
使用event.id代替event.body.id。
Shouldn't it be like this? 难道不是这样吗?
ExpressionAttributeValues: {
":id" : event.id,
":password" : event.password
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.