DynamoDB query error: Multiple Validation Error
DynamoDB query error: Multiple Validation Error
您好,我真的不知道如何解决这个问题。在 Lambda 中进行测试时,我不断收到多个验证错误。我正在四处搜索,有人说要更新到我所做的最新 SDK,但仍然收到相同的错误。我试过在 new AWS.DynamoDB.DocumentClient(); 中使用其他 api。但我的日志中只是 returns 未定义。我怎样才能让我的代码从 DynamoDB 查询?
'use strict';
var APP_ID = "amzn1.echo-sdk-ams.app.ca7e2a16-1bf9-4b5b-8a7e-8c15fb0ccd9d";
var AlexaSkill = require('./AlexaSkill');
var SatTracker = function () {
AlexaSkill.call(this, APP_ID);
};
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var doc = require("dynamodb-doc");
var dynamodb = new AWS.DynamoDB.DocumentClient();
function getZipcode(zipcode) {
var queryParams = {
TableName : "ZipcodeUSA",
KeyConditionExpression: "#zc = :zip",
ExpressionAttributeNames:{
"#zc": "zipcode"
},
ExpressionAttributeValues:{
":zip":zipcode
}
};
console.log("about to start dynamoDB query with zipcode: " + zipcode);
dynamodb.query(queryParams, function(err, data) {
if (err) {
console.log("error in dynamo.query of getZipcode funtion: " + err);
} else {
var zipData;
console.log("starting dynamoDB query with zipcode: " + zipcode);
if (data && data.Items && data.Items.length > 0) {
console.log("Found " + data.Items.length + " matching zipcode");
if (data.Items.length === 1) {
zipData = data.Items[0];
return zipData;
}
}
}
console.log("completed dynamo.query with zipcode: " + err);
});
}
确保传递给 ExpressionAttributeValues 的邮政编码实际上是一个对象。
假设邮政编码是一个字符串,它应该是这样的:
var queryParams = {
TableName : "ZipcodeUSA",
KeyConditionExpression: "#zc = :zip",
ExpressionAttributeNames:{
"#zc": "zipcode"
},
ExpressionAttributeValues:{
":zip": { "S" : zipcode } // S if your zip code is a String N if its a number
}
};
希望对您有所帮助
您好,我真的不知道如何解决这个问题。在 Lambda 中进行测试时,我不断收到多个验证错误。我正在四处搜索,有人说要更新到我所做的最新 SDK,但仍然收到相同的错误。我试过在 new AWS.DynamoDB.DocumentClient(); 中使用其他 api。但我的日志中只是 returns 未定义。我怎样才能让我的代码从 DynamoDB 查询?
'use strict';
var APP_ID = "amzn1.echo-sdk-ams.app.ca7e2a16-1bf9-4b5b-8a7e-8c15fb0ccd9d";
var AlexaSkill = require('./AlexaSkill');
var SatTracker = function () {
AlexaSkill.call(this, APP_ID);
};
var AWS = require('aws-sdk');
AWS.config.update({region: 'us-east-1'});
var doc = require("dynamodb-doc");
var dynamodb = new AWS.DynamoDB.DocumentClient();
function getZipcode(zipcode) {
var queryParams = {
TableName : "ZipcodeUSA",
KeyConditionExpression: "#zc = :zip",
ExpressionAttributeNames:{
"#zc": "zipcode"
},
ExpressionAttributeValues:{
":zip":zipcode
}
};
console.log("about to start dynamoDB query with zipcode: " + zipcode);
dynamodb.query(queryParams, function(err, data) {
if (err) {
console.log("error in dynamo.query of getZipcode funtion: " + err);
} else {
var zipData;
console.log("starting dynamoDB query with zipcode: " + zipcode);
if (data && data.Items && data.Items.length > 0) {
console.log("Found " + data.Items.length + " matching zipcode");
if (data.Items.length === 1) {
zipData = data.Items[0];
return zipData;
}
}
}
console.log("completed dynamo.query with zipcode: " + err);
});
}
确保传递给 ExpressionAttributeValues 的邮政编码实际上是一个对象。 假设邮政编码是一个字符串,它应该是这样的:
var queryParams = {
TableName : "ZipcodeUSA",
KeyConditionExpression: "#zc = :zip",
ExpressionAttributeNames:{
"#zc": "zipcode"
},
ExpressionAttributeValues:{
":zip": { "S" : zipcode } // S if your zip code is a String N if its a number
}
};
希望对您有所帮助