3

I am trying to select an entry from my database with id "1" (primary key) I am not sure what I am doing wrong, I also tried .getItem() method however with no positive result.

'use strict';

var AWS = require('aws-sdk'),
    documentClient = new AWS.DynamoDB.DocumentClient(); 

exports.selectStatus = function(event, context, callback){
    documentClient.query({TableName : "users", Key:{"id":"1"}}, function(err, data){
        if(err){
            callback(err, null);
        }else{
            callback(null, data.Items);
        }
    });
}

I am trying to build serverless REST API using AWS lambda, .scan() works perfectly but I want to filter the data. I have 2 values for each user in database, id(primary key(string)) and status (string).

FIXED UPDATE:

'use strict';

var AWS = require('aws-sdk'),
    documentClient = new AWS.DynamoDB.DocumentClient(); 

exports.selectStatus = function(event, context, callback){
var params = {
    TableName : "users",
    KeyConditionExpression: "id = :id",
    ExpressionAttributeValues: {
        ":id": "1"
    }
};
    documentClient.query(params, function(err, data){
        if(err){
            callback(err, null);
        }else{
            callback(null, data.Items);
        }
    });
}
notFake7
  • 140
  • 1
  • 12

0 Answers0