Skip to content

Only a few items are returned from DynamoDB when using batch GraphQL inserts via AWS Amplify API Playground

0

I’ve built an app that retrieves data from a DynamoDB table using AWS Amplify. Initially, I inserted a small number of Project records (~15) using the DynamoDB console ("Create item" + JSON input), and my app was able to retrieve and display all of them correctly.

To scale this up, I needed to insert around 460 projects. Since my app was already deployed with Amplify, I used the Amplify Studio → Data → API Playground to insert multiple records at once via a GraphQL mutation. Example:

mutation MyMutation {
  project1: createProject(input: {
    projectName: """Project A""",
    projectCode: "PA001",
    id: "1",
    clientID: "1"
  }) {
    clientID
    createdAt
  }

  project2: createProject(input: {
    projectName: """Project B""",
    projectCode: "PB001",
    id: "2",
    clientID: "2"
  }) {
    clientID
    createdAt
  }
}

After executing the full mutation for all 460 projects, I confirmed that all records appear correctly in DynamoDB.

However, when my app queries for projects associated with a specific client (e.g., clientID = 2), it only retrieves a few results (e.g., 2 out of 15 expected). If I manually insert the missing projects via the DynamoDB console, they are correctly retrieved by the app.

What I’ve tried: Double-checked that the clientID values match between app queries and inserted data. Confirmed all projects are stored in DynamoDB with correct fields. Manually added projects via the console → works fine. Queried directly via Amplify Studio API Playground → also returns partial results.

Question: Why are only a subset of the Project records retrieved when using batch createProject mutations via the Amplify API Playground, even though all records are visible in DynamoDB? Is there a caching, resolver, or sync configuration I might be missing?

1 Answer
1
Accepted Answer

The issue you're experiencing with retrieving only a subset of your Project records is likely related to DynamoDB's batch operation limitations and possibly some caching in your Amplify application.

When using batch operations in DynamoDB, there are important constraints to be aware of:

  1. BatchGetItem operations have a limit of 100 items per request. If you're trying to retrieve more than 100 items in a single operation, you'll need to implement pagination or multiple requests.

  2. There's also a 1 MB size limit for the response. If your response exceeds this size, DynamoDB returns partial results along with an UnprocessedKeys value that you can use to retrieve the remaining items.

  3. When the response size limit is exceeded, DynamoDB automatically adjusts the number of items returned per page to enforce this limit. For example, even if you request 100 items but each item is large, the system might return fewer items.

Additionally, Amplify might be caching some part of your build process or query results. This can cause your deployed application to use stale data even when the underlying DynamoDB table has been updated.

To resolve this issue, you could:

  1. Implement pagination in your queries to handle large datasets more effectively.

  2. Check if you need to clear any caches in your Amplify application. This might involve modifying your build settings (amplify.yml) to temporarily disable caching.

  3. Ensure your GraphQL resolvers are properly configured to handle the volume of data you're working with.

  4. If you're using a specific retrieval configuration, check if you need to adjust parameters like numberOfResults to ensure all records are returned.

  5. Monitor your application for any throttling or capacity-related errors that might indicate you're hitting DynamoDB's provisioned throughput limits.
    Sources
    DynamoDB AWS SDK SdkIterable taking time to iterate | AWS re:Post
    BatchGetItem - Amazon DynamoDB
    How do I prevent my deployed amplify app from using a stale/outdated version of my backend? | AWS re:Post

answered a year ago
AWS
SUPPORT ENGINEER
reviewed a year 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.