1

I'm currently having trouble querying a DynamoDB table where the partition key, id, is of type number. This is for a wider project for my own Alexa Skill on AWS. My skill will take as input from the user, a unique id value, which is of slot type AMAZON.NUMBER.

I've looked at the documentation for query and nothing I've tried worked so I decided to start from scratch to a template.

Again, I am just trying to query a table for data based on a partition key called "id" that has a numeric value. The Code below is what I have managed to narrow down as the source of the error.

var params = {
    TableName : "QueryTestTable",
    KeyConditionExpression: "#pkey = :value",
    ExpressionAttributeNames:{
        "#pkey": "id"
    },
    ExpressionAttributeValues: {
        ":value": idNumber
    }
};



return  docClient.query(params, function(err,data) {
    if (err) {
        console.error("Unable to query. Error:", JSON.stringify(err, null, 2));
    } else {
        console.log("Query succeeded.");
        console.log("data = " +  JSON.stringify(data,null,2));
        data.Items.forEach(function(item) {
            console.log(" -", item.id + ": " + item.firstName);
            results += item.id + " has name " +item.firstName + " " + item.lastName + ".\n";
        });
    }
    
    if (results)
        speakOutput = results;
    else
        speakOutput = "Sorry, no result for " + idNumber +" was found in the database.";
   
    return handlerInput.responseBuilder
    .speak(speakOutput)
    .reprompt()
    .withSimpleCard(SKILL_NAME, speakOutput)   //added to generate video output.
    .getResponse();
    
})

enter image description here

I'm just using a simplified version of my table for now. But the above code snippet. For some reason, It keeps skipping to the no entries found in the database statement.

Malcolm
  • 121
  • 3
  • 1
    What is the error you're seeing? What does the table look like? – Maurice Nov 17 '21 at 15:34
  • @Maurice I added a picture of my table and more of the code. I'm using a simiplified version of my table at the moment. But I think I narrowed it down to my syntax in the params object. Correct me if I'm wrong. But so far, I enter a numeric value and keeps telling me it couldn't find anything match. – Malcolm Nov 17 '21 at 15:45
  • @Maurice Thanks for the edit. Do you see anything wrong? Or can you point me towards any documentation that might help? – Malcolm Nov 17 '21 at 20:28
  • 1
    @Malcolm What is the value of ìd`? Make a log output to see for what you are searching. Maybe you don't search for 23 or 21? Or try with a fix number in the first try. – timguy Nov 19 '21 at 10:44
  • @Malcolm 1. Numeric value that you are seeing might not be of type Number. You can view table definition in a different view and check there if it is indeed a Number, or you can open the item and check the DDB Raw format. You can post here one or the other as a proof that it is Number. 2. What is the error output? Or your logs output? 3. As timguy already mentioned try hard-coded values and add some logging. – Cell Nov 27 '21 at 18:18
  • Also I am wondering if this is a case of eventual consistency? If you are writing an item into table and trying to read it fast after that you can try using strongly-consistent reads. – Cell Nov 27 '21 at 18:56

0 Answers0