Interview Prep/AWS/RDS, Aurora and DynamoDB

A DynamoDB `Query` with a filter returns only 12 items, but you know there are hundreds.

BeginnerTroubleshootingRDS, Aurora and DynamoDB
Answer

Likely causes → Each Query or Scan page reads at most 1 MB before the FilterExpression is applied. The response has a LastEvaluatedKey, and the code does not paginate.

Diagnose →

aws dynamodb query --table-name orders --key-condition-expression 'customerId=:c' \
  --filter-expression '#s=:s' --expression-attribute-names '{"#s":"status"}' \
  --expression-attribute-values '{":c":{"S":"c-9"},":s":{"S":"OPEN"}}' --no-paginate \
  --query '[Count,ScannedCount,LastEvaluatedKey]'

Fix →

  1. Loop until LastEvaluatedKey is empty (the CLI paginates by default; SDKs have paginators)
  2. If the filter discards most items, add a GSI keyed on that attribute so you query instead of filter

Prevent → Always use paginators, and compare ScannedCount with Count in reviews; a big gap means the key design is wrong.

aws All AWS questions Roadmap: AWS core services

More on RDS, Aurora and DynamoDB