Skip to content
Anish Karandikar edited this page Apr 30, 2018 · 2 revisions

Pagination in DynamoDB

Get first page of results

aws dynamodb query --table-name realworld-dev-articles --index-name updatedAt \
  --key-condition-expression "dummy = :dummy" \
  --filter-expression 'contains(tagList, :tag)' \
  --expression-attribute-values \
    '{ ":dummy": { "S": "OK" }, ":tag": { "S": "tag_mod_2_0" } }' \
  --projection-expression "tagList" --no-scan-index-forward --max-items 2
{
    "Count": 10,
    "Items": [
        {
            "tagList": {
                "SS": [
                    "tag_18",
                    "tag_mod_2_0",
                    "tag_mod_3_0",
                    "wi37xb"
                ]
            }
        },
        {
            "tagList": {
                "SS": [
                    "nnqziw",
                    "tag_16",
                    "tag_mod_2_0",
                    "tag_mod_3_1"
                ]
            }
        }
    ],
    "NextToken": "eyJFeGNsdXNpdmVTdabcdEtleSI6IG51bGwsICJib3RvX3RydW5jYXRlX2Ftb3VudCI6IDJ9",
    "ScannedCount": 22,
    "ConsumedCapacity": null
}

Get second page of results

Repeat the same query as above, but add --starting-token

aws dynamodb query --table-name realworld-dev-articles --index-name updatedAt \
  --key-condition-expression "dummy = :dummy" \
  --filter-expression 'contains(tagList, :tag)' \
  --expression-attribute-values \
    '{ ":dummy": { "S": "OK" }, ":tag": { "S": "tag_mod_2_0" } }' \
  --projection-expression "tagList" --no-scan-index-forward --max-items 2 \
  --starting-token \
    eyJFeGNsdXNpdmVTdabcdEtleSI6IG51bGwsICJib3RvX3RydW5jYXRlX2Ftb3VudCI6IDJ9
{
    "Count": 0,
    "Items": [
        {
            "tagList": {
                "SS": [
                    "61azpe",
                    "tag_14",
                    "tag_mod_2_0",
                    "tag_mod_3_2"
                ]
            }
        },
        {
            "tagList": {
                "SS": [
                    "5w3s6m",
                    "tag_12",
                    "tag_mod_2_0",
                    "tag_mod_3_0"
                ]
            }
        }
    ],
    "NextToken": "eyJFeGNsdXNpdmVTdGFydEtleSI6xyztbGwsICJib3RvX3RydW5jYXRlX2Ftb3VudCI6IDR9",
    "ScannedCount": 0,
    "ConsumedCapacity": null
}
Clone this wiki locally