amazon-web-services - 是否可以在 Amplify.yml 文件 (AWS Amplify) 中为每个分支设置环境变量?

标签 amazon-web-services environment-variables aws-amplify

我目前正在使用 AWS Amplify 来管理我的前端。我一直在整个控制台中手动注入(inject)环境变量。

虽然我已经看到(至少在这种情况下),但环境变量已得到正确保护,如 AWS docs 中所述.我想知道是否可以在 amplify.yml 文件中为每个分支设置不一定需要保护的变量。

像这样:

version: 0.1
env:
  variables:
    myvarOne:
      branch: master
        value: ad
      branch: dev
        value otherval
frontend:
  phases:
    preBuild:
      commands:
        - yarn install
        - yarn lint
        - yarn test
    build:
      commands:
        - yarn build build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

最佳答案

到目前为止,您的问题似乎还没有理想的解决方案 但是,可以采取一些变通方法来使类似的东西起作用

你不能有每个分支的环境变量,但你可以有每个分支的命令

因此,您可以为不同的分支定义不同的变量,并根据需要运行相应的命令

version: 0.1
env:
  variables:
    myvarOne:
      value_master: val
      value_dev: otherval
frontend:
  phases:
    preBuild:
      commands:
        - if [ "${AWS_BRANCH}" = "master" ]; then export VALUE=${value_master}; fi
        - if [ "${AWS_BRANCH}" = "dev" ]; then export VALUE=${value_dev}; fi
        - yarn install
        - yarn lint
        - yarn test
    build:
      commands:
        - yarn build build
  artifacts:
    baseDirectory: build
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

关于amazon-web-services - 是否可以在 Amplify.yml 文件 (AWS Amplify) 中为每个分支设置环境变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61231233/

相关文章:

python - 在 Windows 中为 Flask 应用程序导出环境变量

amazon-web-services - 在少于配置时间(30 天)后 AWS Amplify "Refresh Token has expired"

javascript - 如何以编程方式在 Cognito 用户池中创建用户?

amazon-web-services - AWS Cognito 使用与 SES 不同的电子邮件提供商

linux - Tomcat 管理器从不问我 ID/PASSWORD

reactjs - 从 AWS Amplify 上托管的 React 应用程序的 protected 路由访问拒绝错误

graphql - 如何将现有的 dynamo db 与 AWS Amplify 和 graphql 结合使用

node.js - 函数 Lambda 的权限被拒绝

android - 如何设置Android环境变量让app继承?

visual-studio-2015 - 如何在 Visual Studio 测试中使用 ASP.NET Core 环境变量