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. When I Run the Same Query with Boto3 on Terminal with the Following Code: Table...
I can query a GSI via DynamoDB console as can be seen in the screenshot.
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.
1 Answer
Your timestamp field is the sort key of the table, so it cannot be used in FilterExpression. It must be part of the KeyConditionExpression.