【问题标题】:DynamoDB query error: Multiple Validation ErrorDynamoDB 查询错误:多重验证错误
【发布时间】:2016-07-16 11:40:44
【问题描述】:

您好,我真的不知道如何解决这个问题。在 Lambda 中进行测试时,我不断收到多个验证错误。我四处寻找,人们说要更新到我所做的最新 SDK,但仍然收到相同的错误。我尝试在 new AWS.DynamoDB.DocumentClient(); 中使用其他 api但这只是在我的日志中返回未定义。如何让我的代码从 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);
    });    
}

【问题讨论】:

  • 你遇到了什么错误?
  • 我收到了多重验证错误,但现在查询停止在未定义处。

标签: javascript amazon-web-services amazon-dynamodb aws-lambda


【解决方案1】:

确保传递给 ExpressionAttributeValues 的邮政编码实际上是一个对象。 假设 zipcode 是一个字符串,它应该是这样的:

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
      }
};    

希望对你有帮助

【讨论】:

    猜你喜欢
    • 2016-08-10
    • 1970-01-01
    • 1970-01-01
    • 2018-09-26
    • 1970-01-01
    • 1970-01-01
    • 2015-10-28
    • 2011-05-22
    • 2018-09-23
    相关资源
    最近更新 更多