[英]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.