AWS scan and query not working as intended

1

Hi,

I have a table in DynamoDB that has approximately 2.2 million entries. I am trying to use the AWS CLI to scan 10 thousand entries from the table. However, the following command:

aws dynamodb scan --limit 10000 --table-name <table_name>

Only returns around 4 thousand entries, with a LastEvaluatedKey. I also tried it with a query command, and I get similar results. Does anyone know why it does not return 10 thousand entries, and how I can fix it? Thanks.

  • Can you run the command with the --debug flag? Does it return all the entries when you remove the --limit param?

  • Why are you scanning for so many items? It is better to export the data to S3 and use Athena to query the data in a richer and more cost-effective way.

asked 2 years ago958 views
2 Answers
3

When you Scan with the CLI pagination happens automatically as described here, however, when you introduce --limit this prevents the CLI from auto-paginating resulting in the request returning the first 1MB worth of data, as described here.

This is further documented in the Scan CLI Docs:

A single Scan operation reads up to the maximum number of items set (if using the Limit parameter) or a maximum of 1 MB of data and then apply any filtering to the results using FilterExpression . If LastEvaluatedKey is present in the response, you need to paginate the result set. For more information, see Paginating the Results in the Amazon DynamoDB Developer Guide .

TLDR:

CLI auto-paginates Scan/Query requests only if you do not provide --limit param, in which case it will return the first 1MB of data.

profile pictureAWS
EXPERT
answered 2 years ago
2

How much data was returned with that 4000 entries? If it exceeds 1 MB then the scan will return less than 1 MB and indicates the pagination with the LastEvaluatedKey.

Quote from our documentation:

DynamoDB paginates the results from Scan operations. With pagination, the Scan results are divided into "pages" of data that are 1 MB in size (or less). An application can process the first page of results, then the second page, and so on.

A single Scan only returns a result set that fits within the 1 MB size limit.

profile pictureAWS
EXPERT
Toni_S
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions