Search code examples
amazon-web-servicesamazon-ec2aws-codepipelineaws-codebuildaws-parameter-store

How to use dynamic key for `parameter-store` in AWS CodeBuild spec file?


I have a buildspec.yml file in my CodeBuild that I want to read values out of EC2 Systems Manager Parameter Store. CodeBuild supports doing this via the parameter-store attribute in your spec file.

Problem is, I can't figure out how to use enviornment Variables that are set BEFORE the buidlspec executes.

Here is an example:

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:  
      ...

As you can see I'm doing the AWS best practice for name-spacing the EC2 Systems Manager Parameter Store keys. I want to re-use this build spec for all my stages, so hard coding is not an option. The vars I use in the Value string are populated as EnvironmentVariables in my CodeBuild project - so they are available before the spec runs.

How do I dynamically populate the Value of the parameter-store Keys with something that is not hard coded?


Solution

  • I found this StackOverflow post - unfortunately the feature you describe does not seem to exist.
    It would have been nice to be able to use parameters and functions akin to the features in CloudFormation templates.