amazon-web-servicesaws-cloudformationaws-api-gatewayaws-amplifyamplifyjs

AWS Amplify Fullstack CI/CD breaks API (cors issues)


I have an Amplify app that is using the AWS REST Express lambda function API. It is connected to the CI/CD so whenever I push to my branch (accept PR's) the app's frontend and backend services are built and deployed.

At this point, whenever I accept PR's / push code, the apps API will stop working. I then have to get on my local code, modify the API's app.js file and do a dummy push. Same code that I just pushed (minus the useless comment) and then the app on both my local machine and the deployed URL starts working again. The frontend build/deploy works fine - it's just the backend build/deploy that causes the API to only return CORS errors.

My question is how to fix my CI/CD so that I don't need to do the extra deployment locally.

Some extra notes - This is a React app with multiple environments deploying on different AWS accounts.


Solution

  • Turns out there was a difference in the API stack being deployed for CLI push and CI/CD deployment.

    The solution was to set my CI/CD Build Image to have the same Amplify CLI as my local version.

    To do so:

    1. Run amplify --version locally to get the version to copy onto Amplify Console
    2. Copy the value in Amplify Console > Build Settings > Build Image Settings > Amplify CLI

    Where to Insert the local Amplify version