Telenoobies
Telenoobies

Reputation: 936

AWS amplify deploy failure due to aws-exports

I am trying to deploy my reactJs app to Amplify. I have my Github connected to Amplify. During deployment it shows the following error at Build step:

2020-01-07T19:35:22.127Z [INFO]: Failed to compile.
2020-01-07T19:35:22.129Z [INFO]: ./src/index.js
                                 Cannot find file './aws-exports' in './src'.
2020-01-07T19:35:22.149Z [WARNING]: error Command failed with exit code 1.
2020-01-07T19:35:22.150Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2020-01-07T19:35:22.155Z [ERROR]: !!! Build failed
2020-01-07T19:35:22.239Z [ERROR]: !!! Non-Zero Exit Code detected
2020-01-07T19:35:22.239Z [INFO]: # Starting environment caching...

This happens because .gitignore ignores aws-exports. Can someone please tell me what's the solution to this problem without committing aws-exports?

Upvotes: 28

Views: 21694

Answers (1)

Pedro Frattezi Silva
Pedro Frattezi Silva

Reputation: 581

I have experienced the same problem in my first build.

The Amplify documentation is not specific about how you should maintain your builds when using the Amplify Console, but the routine that worked for me was:

You generate your aws-exports file when you run a successful amplify push command.

aws-exports.js file This file is generated only for JavaScript projects. It contains the consolidated outputs from all the categories and is placed under the src directory that the user (the developer) specified during the init process. It is updated after each successful execution of the amplify push command, that has created or updated the cloud resources.

Based on that I updated my configuration in the Amplify console to also deploy my backend. You can learn how to configure your own at https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html

backend:
  phases:
    build:
      commands:
        - '# Execute Amplify CLI with the helper script'
        - amplifyPush --simple

After the backend build is done the file is generated for my next job which is the frontend build that consumes the aws-exports file.

Note: If you're using eslint you can have a problem with the file output format. You can add a eslint --fix command in your frontend preBuild

Update: As lucdenz mentioned, you also need to setup a service role

Sources I used:

Upvotes: 36

Related Questions