1
votes

I have data in dynamoDB table and am trying to filter it based on data attributes. Below is an example of the JSON data. An example for filter query would be: payload.stat > 200.

However, attempts to use such query in DynamoDB navigation pane does not work and I get error: "An item consists of one or more attributes. Each attribute consists of a name, a data type, and a value. When you read or write an item, the only attributes that are required are those that make up the primary key"

How can I filter the data using attributes within payload?

{
  "payload": {
    "lock": "L1",
    "maxtmptr": 50,
    "serial": "SX001",
    "stat": 255,
    "timeover": 0.17,
    "tmptr": 30
  },
  "serial": "SX001",
  "timestamp": "1472784542467"
}

Screenshot of DynamoDB Table:

Click here for snapshot of DynamoDB Table

1
What is the datatype of payload? Is it defined as map? - notionquest
Can you share your code which throws out this error? - Dasharath
@notionquest, payload is a json data. no need to define payload . - Abdul Manaf

1 Answers

2
votes

You can query or scan the result using FilterExpressions. When you query the dynamodb, partition key is must. When you scan the dynamodb, partition key is optional. But Scan is slower than Query.

Try with this

var params = {
        "TableName": tableName,
         "FilterExpression": "payload.lock = :val1 and timestamp = :val2",
        "ExpressionAttributeValues": {
            ":val1": "lockInput",
            ":val1": "timestamp"
        },
        "ReturnConsumedCapacity": "TOTAL"
    };

if you need more filter options, you can customize your FilterExpression.