Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS amplify deploy failure due to aws-exports

Tags:

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?

like image 903
Telenoobies Avatar asked Jan 12 '20 22:01

Telenoobies


People also ask

How do I update AWS exports amplify?

To autogenerate aws-exports.js at build-timeSign in to the AWS Management Console and open the Amplify console . Choose the app to edit. Choose the Hosting environments tab. Locate the branch to edit and choose Edit.

How do I redeploy AWS amplify?

To manually deploy an app from Amazon S3 or a public URLSign in to the AWS Management Console and open the Amplify console . At the top of the page, choose Get started. In the Deliver section, choose Get started. On the Host your web app page, choose Deploy without Git provider.

Does AWS amplify use a CDN?

AWS Amplify will build and deploy your web app quickly, and host your web app on a globally available content delivery network (CDN) with a friendly URL (example: https://master.appname.amplifyapp.com). To get started, go to AWS Amplify on the AWS console.


1 Answers

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:

  • https://aws-amplify.github.io/docs/cli-toolchain/usage#aws-exportsjs-file
like image 105
Pedro Frattezi Silva Avatar answered Sep 28 '22 07:09

Pedro Frattezi Silva