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.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.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest