当我在 Amplify 中运行 CodeBuild 时,我的 AppSync 凭据被覆盖,从而破坏了构建。
我正在使用 AWS Amplify 作为后端构建一个 ReactJS 网站。该项目正在使用 Amplify 内置 CodeBuild 进行部署。AppSync API 是为 Amplify 单独创建的,不会直接出现在 Amplify 控制台中。
当我运行时amplify codegen add --apiId xxx,aws-exports.js会生成文件,其中包含以下字段:
const awsmobile = {
"aws_project_region": "eu-west-2",
"aws_appsync_graphqlEndpoint": "https://xxxxx.appsync-api.eu-west-2.amazonaws.com/graphql",
"aws_appsync_region": "eu-west-2",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "xxxxx"
};
Run Code Online (Sandbox Code Playgroud)
但是,当 Amplify Frontend CodeBuild 作业运行时,AppSync 字段不存在。amplifyPush --simple在后端作业期间运行会aws-exports.js使用以下内容覆盖该文件:
const awsmobile = {
"aws_project_region": "eu-west-2"
};
Run Code Online (Sandbox Code Playgroud)
amplifyPush --simple这与该命令似乎生成的格式相同。这样做的结果是在构建过程中,React 找不到它需要的变量。
> react-scripts build
[INFO]: Creating an optimized production build... …Run Code Online (Sandbox Code Playgroud) amazon-web-services reactjs aws-codebuild aws-appsync aws-amplify