简体   繁体   English

由于 aws-exports,AWS 放大部署失败

[英]AWS amplify deploy failure due to aws-exports

I am trying to deploy my reactJs app to Amplify.我正在尝试将我的 reactJs 应用程序部署到 Amplify。 I have my Github connected to Amplify.我将我的 Github 连接到 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.发生这种情况是因为.gitignore忽略了 aws-exports。 Can someone please tell me what's the solution to this problem without committing aws-exports?有人可以在不提交 aws-exports 的情况下告诉我这个问题的解决方案是什么吗?

I have experienced the same problem in my first build.我在第一次构建时遇到了同样的问题。 Since aws-exports contains sensitive information you are right by adding it to your .gitignore file.由于aws-exports包含敏感信息,因此将其添加到 .gitignore 文件是正确的。

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: Amplify 文档没有具体说明在使用 Amplify 控制台时应该如何维护构建,但对我有用的例程是:

You generate your aws-exports file when you run a successful amplify push command.当您运行成功的amplify push命令时,您将生成aws-exports文件。

aws-exports.js file This file is generated only for JavaScript projects. aws-exports.js 文件此文件仅为 JavaScript 项目生成。 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.它包含所有类别的合并输出,并放置在用户(开发人员)在 init 过程中指定的 src 目录下。 It is updated after each successful execution of the amplify push command, that has created or updated the cloud resources.它在每次成功执行 amplify push 命令后更新,即已创建或更新云资源。

Based on that I updated my configuration in the Amplify console to also deploy my backend.基于此,我更新了 Amplify 控制台中的配置以部署我的后端。 You can learn how to configure your own at https://docs.aws.amazon.com/amplify/latest/userguide/build-settings.html您可以在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.后端构建完成后,将为我的下一个工作生成文件,即使用aws-exports文件的前端构建。

Note: If you're using eslint you can have a problem with the file output format.注意:如果您使用的是 eslint,则文件输出格式可能会出现问题。 You can add a eslint --fix command in your frontend preBuild您可以在前端preBuild添加eslint --fix命令

Update: As lucdenz mentioned, you also need to setup a service role更新:正如lucdenz提到的,您还需要设置一个服务角色

Sources I used:我使用的来源:

I struggled with this issue for quite some time.我在这个问题上挣扎了很长一段时间。 I finally figured it out.我终于弄明白了。 I created an article to explain it all here: https://medium.com/@gbarnhardt/defeat-the-amplify-nextjs-ssr-infamous-aws-exports-error-7cbade8fe036?sk=658df416a92db5148d0dd6f1c2a3a2da我在这里创建了一篇文章来解释这一切: https : //medium.com/@gbarnhardt/defeat-the-amplify-nextjs-ssr-infamous-aws-exports-error-7cbade8fe036?sk=658df416a92db5148d0dd6f1c2a3a2da

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM