ryn*_*nop 5 amazon-ec2 amazon-web-services aws-codepipeline aws-codebuild aws-parameter-store
我的 CodeBuild 中有一个 buildspec.yml 文件,我想从 EC2 Systems Manager Parameter Store 中读取值。CodeBuild 支持通过parameter-store规范文件中的属性执行此操作。
问题是,我不知道如何使用在执行 buidlspec 之前设置的环境变量。
下面是一个例子:
version: 0.2
env:
variables:
RUNTIME: "nodejs8.10"
#parameter-store vars are in the format /[stage]/[repo]/[branch]/[eyecatcher]/key
parameter-store: #see https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html#build-spec-ref-syntax
LAMBDA_EXECUTION_ROLE_ARN: "/${STAGE}/deep-link/${BRANCH}/GetUri/lambdaExecutionRoleArn"
ENV_SAMPLE_KEY: "/${STAGE}/deep-link/${BRANCH}/GetUri/key1"
phases:
install:
commands:
...
Run Code Online (Sandbox Code Playgroud)
如您所见,我正在执行 AWS 最佳实践,以对 EC2 Systems Manager Parameter Store 密钥进行命名间距。我想在我的所有阶段重复使用这个构建规范,所以硬编码不是一种选择。我在Value字符串中使用的变量EnvironmentVariables在我的 CodeBuild 项目中填充- 因此它们在规范运行之前可用。
如何使用非硬编码的东西动态填充Value参数存储Keys?
CodeBuild 现在支持此变量扩展以用于参数存储用例。您可以在构建规范中定义任何环境变量,并在获取参数存储的路径中引用该变量。
version: 0.2
env:
variables:
stage: PRE_PROD
parameter-store:
encryptedVar: CodeBuild-$stage
phases:
build:
commands:
- echo $encryptedVar
Run Code Online (Sandbox Code Playgroud)
我发现了这篇 StackOverflow 帖子- 不幸的是,您描述的功能似乎不存在。
如果能够使用类似于 CloudFormation 模板中的功能的参数和函数,那就太好了。
| 归档时间: |
|
| 查看次数: |
5294 次 |
| 最近记录: |