How do I prevent my deployed amplify app from using a stale/outdated version of my backend?

0

I am developing a nextJS app using amplify/appsync/dynamodb.

The deployed app seems to be using a stale version of data stored in dynamodb. The original data set only included 7 records. I added 25 new records but the deployed app still only shows the original 7.

My local environment shows all 32. I can see all 32 records in the database. I can see all 32 records in data manager and when I test the GraphQL API in Amplify Studios data manager, I get all 32 to records.

I've tried redeploying the backend. I don't have API cacheing turn on. I don't see any errors in cloud formation. And I'm not using any cloudfront distributions. There is a cloudfront URL being used for the app though, I think amplify automatically created it when I connected Amplify to github and chose to use a custom domain. All the custom domains and the Amplify App url show the old records (the 7 records). Only my local frontend shows the correct number of records.

Any help figuring out the mismatch is appreciated.

Test query local version Deployed version

  • Also, I just created 2 additional urls, staging and develop, that are tied to the staging and develop branches of my github repository. Both of the new branches/domains are using the same api and tables as the original and both show the correct amount of new records. So it seems like something with the original is being cached somewhere but I can't tell where/how.

1 Answer
0
Accepted Answer

I'm going to answer my own question as I figured out the issue and solution after not finding it elsewhere. I verified the following:

  • The appsync api for the local environment and the deployed environment match.
  • The dynamodb configuration for the local environment and the deployed environment match.
  • Redeploying the backend numerous times didnt resolve the issue.

Ultimately I realized that something was being cached when my local environment was up to date while the deployed environments were not. Amplify was caching some part of the build process that included the previous iteration of dynamodb. I had to modify the build settings (amplify.yml) so that it would temporarily stop caching. Specifically this was the original/previous version of amplify.yml

version: 1
backend:
  phases:
    build:
      commands:
        - npm ci --cache .npm --prefer-offline
        - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
  phases:
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - .next/cache/**/*
      - .npm/**/*

and I modified it to this

version: 1
backend:
  phases:
    build:
      commands:
        - rm -rf .npm  # Clear npm cache to ensure fresh dependencies
        - npm ci --cache .npm --prefer-offline
        - npx ampx pipeline-deploy --branch $AWS_BRANCH --app-id $AWS_APP_ID
frontend:
  phases:
    preBuild:
      commands:
        - rm -rf .next/cache  # Clear Next.js cache to ensure fresh build
        - rm -rf .npm  # Clear npm cache to ensure fresh dependencies
    build:
      commands:
        - npm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths: []
    # Temporarily disable caching during this deployment
    # Re-enable it in the future by restoring the paths below:
    # paths:
    #   - .next/cache/**/*
    #   - .npm/**/*
caveman
answered 25 days 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