尝试使用boto get_paginator
进行query
操作来实现分页。我找不到正确的方法,如果没有加载前两页的内容,可以说是第3页的页面:
import boto3
from boto3.dynamodb.conditions import Key, Attr
dynamodb = boto3.resource("dynamodb", region_name="us-west-2")
paginator = dynamodb.meta.client.get_paginator("query")
pages = paginator.paginate(TableName="results",
IndexName="year-timestamp-index",
KeyConditionExpression=Key("year").eq("2017"),
PaginationConfig={"PageSize": 50})
def get_content_of_page(requested_page_num, pages):
pages_counter = 0
for page in pages:
if pages_counter == requested_page_num - 1:
return page.get("Items")
pages_counter += 1
get_content_of_page(pages, 3) # will load and skip contents of
# 2 pages and return content of 3rd
我认为它太贵了,是否有可能直接获得第3页?
像Mongo的cursor.skip(page_size * (requested_page_num - 1)).limit(page_size)