1

嗨我真的不知道如何解決這個問題。在Lambda中測試時,我不斷收到多個驗證錯誤。我在四處搜尋,有人說要更新到我所做的最新SDK,但仍然收到相同的錯誤。我試過在新的AWS.DynamoDB.DocumentClient()中使用其他apis;但是這只是在我的日誌中返回undefined。如何讓我的代碼從DynamoDB查詢?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); 
    });  
} 
+1

你得到什麼錯誤? –

+0

我得到一個multiplevalidationerror但現在查詢只是停在未定義。 –

回答

1

確保您傳遞給您的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 
     } 
};  

希望這有助於