skip to Main Content

I want to show all the results of a particular table that im querying through the aws cli and this is how i structured the code.

aws dynamodb scan --table-name core_samples --debug

This gives me back a table but its not showing all my results. So i resorted to pagination and I want to know how to add the ExclusiveStartKey from the LastEvaluatedKey as my parameters so that i could enter the code over again until I’ve gotten all the results of the table. The following is how i thought i was supposed to do it but it gave me a couple of errors.

aws dynamodb scan 
    --table-name core_samples 
    --ExclusiveStartKey <providedkey> 
    --debug

or

aws dynamodb scan 
    --table-name core_samples 
    --starting-token <providedkey> 
    --debug

How do i do it?

2

Answers


  1. The docs for the AWS CLI for DynamoDB are at https://docs.aws.amazon.com/cli/latest/reference/dynamodb/scan.html

    Using the CLI you don’t get a LastEvaluatedKey, you get a NextToken and pass it back with --starting-token. The model follows the generic paging system across services with the CLI rather than being DynamoDB-specific:

    --starting-token (string)

    A token to specify where to start paginating. This is the NextToken 
    from a previously truncated response.
    
    For usage examples, see Pagination in the AWS Command Line Interface
    User Guide.
    

    The CLI pagination docs are at https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-pagination.html

    It mentions you can opt to do client-side paging as well, like using less which is pretty cool. Or you can set the pager to empty to just have it auto-page and scan til it’s done.

    Login or Signup to reply.
  2. The AWS CLI implements pagination by default in DynamoDB, which is unlike the other SDK’s which force client side pagination. This means you have no need to use LastEvaluatedKey or ExclusiveStartKey unless you are stopping the request early by using Limit or FilterExpression.

    It seems here you are not limiting your requests, so I would expect all data to be returned. Ensure you check your tables data using the web console and understand that it contains the items which you expect from your CLI command.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search