Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB: Filter Expression can only contain non-primary key attributes

I can query a GSI via DynamoDB console as can be seen in the screenshot.

Screenshot: the query

When I run the same query with Boto3 on terminal with the following code:

table.query(
    IndexName='date-timestamp-index',
    KeyConditionExpression=Key('date').eq('20161231'),
    FilterExpression=Attr('timestamp').between(1483130000, 1483133600) & Attr('tags').exists()
)

I get a ValidationException exception:

Filter Expression can only contain non-primary key attributes: Primary key attribute: timestamp

What am I doing wrong here? Thanks.

like image 798
onurmatik Avatar asked Jan 14 '17 02:01

onurmatik


1 Answers

Your timestamp field is the sort key of the table, so it cannot be used in FilterExpression. It must be part of the KeyConditionExpression.

like image 131
Dasharath Avatar answered Oct 26 '22 20:10

Dasharath