8
votes

I am trying to do a simple dynamoDB scan with a filter expression (documentation here)

This is my expression string:

"attribute_exists("my_db_key") AND ("my_db_key" = 1)"

This simply states:

"If a value for my_db_key exists AND my_db_key EQUALS 1, return it in the results"

However it does not work and I get a this error:

Invalid FilterExpression: Syntax error; token: "1", near: "= 1)

I am aware that I can use an attribute value placeholder for values and then use that in the expression but I do not want to do this. And according to Amazon's documentation it is NOT required.

So how do I do this simple expression? Does anyone have an example or link to documentation? Amazon's documentation is unfortunately of no help.

NOTE: I am implementing this with AWSDynamoDBScanInput on iOS but my issue here is to do with global expression syntax so it should not matter.

2

2 Answers

5
votes

Your params need to look something like this (for the Node AWS library):

params = {
  "FilterExpression": 'attribute_exists("my_db_key") AND ("my_db_key" = :value)',
  "ExpressionAttributeValues": {
    ":value": 1
  },
  // ...
};

docClient.scan(params, function(err, data){
  // Handle err or process data
})

For some languages, the parameters should look more like this:

{
  "FilterExpression": 'attribute_exists("my_db_key") AND ("my_db_key" = :value)',
  "ExpressionAttributeValues": {
    ":value": {"N":1}
  },
  // ...
};
2
votes

You have to use a placeholder and pass the value separately. Here's some documentation and a Post from AWS forums