是否可以在 AWS 管道中的 React 应用程序中引用 codebuild 中定义的环境变量?

Is is possible to reference env variables defined in codebuild inside a react app that you have in the pipeline on AWS?

我的 buildspec.yml 文件有以下两个环境变量,我从机密管理器中提取它们:

问题:我这样做是因为我不想让配置文件带有 url 并将其放在 github 中。我希望在我的 buildspec.yml 文件中引用它,然后在构建后将其拉入我的 React 应用程序。我怎样才能做到这一点?

version: 0.2

env:
  secrets-manager:
    key: API-Gateway-URL-DEV:URL
    key: API-Gateway-URL-DEV:REGION
phases:
  install:
    runtime-versions:
      nodejs: 12

您需要将这些值放入与您的应用一起部署的文件中。一种方法是使用 jq 替换文件中的值,甚至写出一个全新的文件。所以基本上你不想签入的配置文件(明智!)应该在你的构建中 created/updated。