What cases will cause AppSync to not return all matching records/items from the DynamoDB table?

Viewed 939

We're seeing some odd behaviors where not all the items are being returned in an AppSync query. There are 31 items in the database table, but the following query only returns 10 items?

query listAllDocuments {
        listDocuments {
          items{
            userId
          }
      }
  }

It's a simple DynamoDB resolver:

{
    "version" : "2017-02-28",
    "operation" : "Scan",
    "filter": #if($ctx.args.filter) $util.transform.toDynamoDBFilterExpression($ctx.args.filter) #else null #end,
}

Other queries (that use the filter) also return some sub-set of the actual matching documents.

2 Answers

Not sure you pasted all resolver code. If you are using autogenerated listX resolver, it by default returns 10 items. Try

query listAllDocuments {
        listDocuments(limit: 100) { // anything larger than 31
          items{
            userId
          }
      }
  }

And you will get all 31. Find more details in the github thread

There is a default limit of 10 when using scan to prevent you from browning out your table. In your VTL Mapping Template, specify a higher limit to get all the items. See https://docs.aws.amazon.com/appsync/latest/devguide/resolver-mapping-template-reference-dynamodb.html#aws-appsync-resolver-mapping-template-reference-dynamodb-scan to specify this limit. You can set the limit as high as you want; DynamoDB will stop once it reaches the total number of items in the table or the limit, whichever is smaller.

Related