Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Missing required key 'Key' in params" in Get operation of Dynamo dB

I am writing Lambda function in node.js to getitems from dynamodB. Table is employee where emo_Id is the Partition key. Below is the code snippet 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 am getting is : "message": "Missing required key 'Key' in params", "code": "MissingRequiredParameter",

I know the resolution of the error is to add: Key:{ "emp_Id": emp_Id, } to the code. But If I have to query the employees who have joined after a particular date then I cannot provide emp_Id as a parameter.

In the AWS release notes I have found that we can disable parameter validation, https://aws.amazon.com/releasenotes/6967335344676381 I tried this but this is also not working.

Can somebody please help?

Thanks Shweta

like image 980
shweta dixit Avatar asked Mar 23 '17 06:03

shweta dixit


2 Answers

I ran into this when I first started with DynamoDb. Such an annoying error. Turns out I had accidentally used the .get method, from a previous working getById example, instead of the .query method.

In short, you may just need to change this ...

const response = await db.get(query).promise();

... to this ...

const response = await db.query(query).promise();

like image 109
Fred Lackey Avatar answered Nov 11 '22 22:11

Fred Lackey


I was hit with a same error when querying the secondary indexes. Turns out that I was using the wrong API. Confused between getItem and Query.

like image 16
user 923227 Avatar answered Nov 11 '22 22:11

user 923227