How to properly configure Amplify CI/CD pipeline when using multiple frontends (aws-exports is missing for frontend builds)?

Viewed 747

I'm stuck trying to configure a very simple CI/CD pipeline to automatically deploy my frontend application on Amplify. I get an error during the build step.

To make the long story short :

  • I created a simple project to host my Amplify backend config (it contains only a basic Cognito configuration and a GraphQL Api with only one model : Todos)
  • Then I created another project to store a frontend app (a React application)
  • I pulled the backend configuration to this frontend project (amplify pull command) and added the whole imports to load Amplify dependencies in my index.js file (including the aws-exports config file). Everything works well locally.
import Amplify from "aws-amplify";
import awsExports from "./aws-exports";
Amplify.configure(awsExports);
  • I connected my frontend Github repository to Amplify CI/CD though the Web Console to automatically deploy my app each time I push new commits to my dev branch. It worked well the first time when I didn't add yet the Amplify configuration in my index.js file. For sure, I configured my frontend (trough the Web UI) to connect link this one to the target backend environment dev

Git Ignore :

Please note : the aws-exports file is ignored thanks to git ignore. I would suppose the CI/CD pipeline should automatically add the configuration when assigning the target backend environment to this frontend env.

Web Form to assign target backend environment

Here is the error (build logs) :

2021-03-05T08:20:33.144Z [INFO]: ./src/index.js
                                 Cannot find file './aws-exports' in './src'.
2021-03-05T08:20:33.155Z [WARNING]: npm
2021-03-05T08:20:33.155Z [WARNING]: ERR! code ELIFECYCLE
                                    npm ERR! errno 1
2021-03-05T08:20:33.157Z [WARNING]: npm

From my understanding, the Amplify CI/CD service doesn't propagate properly the configuration of the backend before building the frontend app (in my case a Node.js / React stack)

Any idea to solve this issue ?

BTW : Do you know if we could configure the provisioning step. I didn't find any information for example to stop the container or to resize the instance. I don't want to run in on a 24/24 basis and the basic config consume too much resources for my needs.

Kind regards,

1 Answers
Related