Query function with Lambda and DynamoDB

时间:2015-07-28 16:01:21

标签: jquery json lambda amazon-dynamodb

Newbie for dynamodb and trying to get new lambda function to query table.

Can someone help me out and tell me what is wrong with the son that I am passing to the .query function. Client_ID is my hash key on the table(String)

{
    "TableName": "table1",
     "KeyConditions": {
        "Client_ID": {
            "ComparisonOperator": "EQ",
            "AttributeValueList":[
                {"S": "12345"}
            ]
        }
    }
}

When testing i get error back

"errorMessage": "Need to pass in a valid Condition Object."

1 个答案:

答案 0 :(得分:1)

Are you using the DynamoDB Document SDK or low level SDK? It seems like you are using the Document SDK (https://github.com/awslabs/dynamodb-document-js-sdk), in which case you should use the Condition object instead to specify the Key Conditions (i.e. KeyConditions = [docClient.Condition("Client_ID", "EQ", "12345")]) . An easier way to specify KeyConditions is to use the KeyConditionsExpression parameter instead (documented here: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-KeyConditionExpression). Then your params would look like: { "TableName": "table1", "KeyConditionExpression": "Client_ID = :str", "ExpressionAttributeValues": {":str": "12345"} }