Reputation: 474
I have clear code for ordering a DynamoDB scan by ascending or descending using the
response = table.query(
ScanIndexForward=False # true = ascending, false = descending
)
argument. Likewise I have the boto paginator for paginating responses using the following:
paginator = dynamodb.get_paginator('scan')
response_iterator = paginator.paginate(
TableName=table.table_name,
PaginationConfig={"MaxItems": 25, "PageSize": 1}
)
But I am unable to find an optional argument or method to do both. The order returned by the paginator class appears to be random.
Is there a way to order the notifications by ascending or descending and then split into paginated shards?
I have investigated the optional arguments passed to the paginator scan in the documentation but ScanIndexForward is not an optional argument on SCAN and there is no ASC or DESC option in the conditions that can be passed to ScanFilter.
The table is created within the python CDK with the following partition and sort keys:
dynamodb.Table(
self,
"NotificationsTable",
partition_key=dynamodb.Attribute(
name="_id", type=dynamodb.AttributeType.STRING
),
sort_key=dynamodb.Attribute(
name="Date", type=dynamodb.AttributeType.NUMBER
)
)
Upvotes: 0
Views: 364
Reputation: 19738
You cannot order a Scan operation as it spans multiple partition keys, each pk will return at random, but in order by its accompanying sort-key. Your original request was a Query
with ScanIndexForward
, this only returns a single partition key ordered by the sort key.
Upvotes: 1