If you you have both a partition key and sort key as your primary key, you need to supply both to the ExclusiveStartKey. Dynamo gives you two options when building a primary key, a partition key, or a composite key (made up of the partition key and sort key). When using a composite key, always need to provide both the partition key and sort key when referencing a single record in the table
From the docs (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_Query_v20111205.html) -
ExclusiveStartKey
- Primary key of the item from which to continue an earlier query. An
earlier query might provide this value as the LastEvaluatedKey if that
query operation was interrupted before completing the query; either
because of the result set size or the Limit parameter. The
LastEvaluatedKey can be passed back in a new query request to continue
the operation from that point.
Type: HashKeyElement, or HashKeyElement and RangeKeyElement for a
composite primary key.
here, HashKeyElement
refers to the partition key, and RangeKeyElement
refers to the sort key
try
ExclusiveStartKey: {
'id': lastKey
'created_at': <last key's created_at value>
}
or it might actually be -
ExclusiveStartKey: lastkey
depending on what you have as lastKey
, it might already be the composite key