Thursday, July 19, 2018

AWS: Using environment variables in CodeBuild buildspec

Source: Using environment variables in AWS CodeBuild buildspec.yml
See S3_BUCKET below, which is first expanded from ImportValue, then used in BuildSpec.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
AvUsageQuarantineBuildProject:
  Type: AWS::CodeBuild::Project
  Condition: Preprod
  Properties:
    Name: av-usage-quarantine-build
    ServiceRole: !GetAtt AvUsageQuarantineBuildProjectRole.Arn
    Artifacts:
      Type: CODEPIPELINE
      Name: av-usage-quarantine
    Environment:
      Type: LINUX_CONTAINER
      ComputeType: BUILD_GENERAL1_SMALL
      Image: aws/codebuild/java:openjdk-8
      EnvironmentVariables:
        - Name: S3_BUCKET
          Value: !ImportValue delivery-AvDeliveryUtilsBucket
    Source:
      Type: CODEPIPELINE
      BuildSpec: !Sub |
        version: 0.2
        phases:
          install:
            commands:
              - cd ~; wget https://raw.github.com/technomancy/leiningen/stable/bin/lein; chmod +x lein; mv lein /bin
              - LEIN_ROOT=true lein
          build:
            commands:
              - cd $CODEBUILD_SRC_DIR
              - LEIN_ROOT=true lein uberjar
          post_build:
            commands:
              - aws cloudformation package --template template.yaml --s3-bucket $S3_BUCKET --s3-prefix lambda --output-template av-usage-quarantine-output-template.yaml