"The required key" Key "is missing in the parameters" in the Dynamo dB mode

I am writing a lambda function in node.js for getitems from dynamodB. The table is employee, where emo_Id is the section key. Below is the piece of code I am writing:

var table = "Employee_Test";
var emp_Id=event.emp_Id;
var emp_Name=event.emp_Name;
var params = {
TableName: table,
    KeyConditionExpression: "#eId = :Id",
        ExpressionAttributeNames:{
            "#eId": "emp_Id"
        },
        ExpressionAttributeValues: {
            ":Id":emp_Id
        }}

      

The error I receive is: "message": "Missing required" Key "in parameters", "code": "MissingRequiredParameter",

I know the solution to the error is to add: Key: {"emp_Id": emp_Id,} to the code. But if I need to query employees who have joined after a certain date, I cannot provide emp_Id as a parameter.

In the AWS release notes, I found that we can turn off parameter validation, https://aws.amazon.com/releasenotes/6967335344676381 I've tried this but that doesn't work either.

Can anyone please help?

Thanks Shweta p>

+3


source to share


2 answers


I had an error with the same error when querying secondary indices. It turns out I was using the wrong API. Confused between getItem and Query.



+2


source


Add a global sub-index to the table to enable start date searches. First, change the item creation code (PutItem) to add an attribute representing the month and year the employee joined, for example joinYearMonth = 201612. Second, scan your table to find items that do not already have this attribute, and add them. Third, create a global secondary index with the joinYearMonth section key and joinTimestamp sort key. Thus, you can issue queries of queries to GSI over the years and months it takes to find those that have joined.



0


source







All Articles