title: AWS CodePipeline: How to pass output from CloudFormation action to a CodeBuild action
body: <p>I have an AWS CodePipeline defined in a CloudFormation template.</p>
  
  <p>One of the steps of the pipeline is a CloudFormation action that builds a test environment for my application. The URL of the app's Elastic Load Balancer is one of the outputs defined in this template.</p>
  
  <p>How do I access this output, so that I can use it in the next step, which is a CodeBuild action that will run api tests against the test environment?</p>
  
  <p>I can specify an <code>OutputFileName</code> in the CloudFormation Deploy step, but the CodeBuild step would then need 2 input artifacts, the test code and the CloudFormation output file, and there is a maximum of 1 input artifact.</p>
  
  <p>I thought that I could have a step that pushes the CloudFormation output file to S3, so that the api test step can then access it (or simply push it to S3 as part of the CloudFormation::Init code), but I am hoping for something more simple that I could configure in the CodePipeline steps (similar to !ImportValue in CloudFormation).</p>
  
  <p>I also thought that I could assign a 'test url' e.g. <a href="http://test.myapp.com" rel="nofollow noreferrer">http://test.myapp.com</a>, in the CloudFormation step so that the api tests are always run against that specific url, which would be a great option, except that I am spinning up the test environment dynamically just before the tests (because I don't want the cost of it always running), and I'm not sure that the DNS will have propagated by the time the api tests start running.</p>
  
  <p>Thanks in advance</p>
  
  <p><em>Definition of CodePipeline CloudFormation action that spins up test environment</em></p>
  
  <pre><code>...
  Name: DeployApplicationInfra
  ActionTypeId:
    Category: Deploy
    Owner: AWS
    Version: 1
    Provider: CloudFormation
  Configuration:
    ActionMode: CREATE_UPDATE
    Capabilities: CAPABILITY_IAM
    OutputFileName: test-application-infra-stack.outputs.json
    StackName: test-application-infra-stack
    RoleArn: !Ref CloudFormationServiceRoleArn
    TemplateConfiguration: AppInfraCfnTemplate::test-application-infra.config.json
    TemplatePath: AppInfraCfnTemplate::application-infra.yml
  InputArtifacts:
    - Name: AppInfraCfnTemplate
  OutputArtifacts:
    -  Name: TestApplicationInfraStackOutputs
  </code></pre>
  
  <p><em>Definition of CodePipeline CodeBuild action to run api tests</em></p>
  
  <pre><code>...
  Name: RunApiTests
  ActionTypeId:
    Category: Test
    Owner: AWS
    Version: 1
    Provider: CodeBuild
  Configuration:
    ProjectName: !Ref ApiTestsBuildProject
  InputArtifacts:
    - Name: AppSource
  
  ...
  ApiTestsBuildProject:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: companyinsight-api-tests-build
      Artifacts:
        Type: CODEPIPELINE
      Environment:
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/nodejs:8.11.0
        Type: LINUX_CONTAINER
      ServiceRole: !Ref CIServerBuildRoleArn
      Source:
        Type: CODEPIPELINE
        BuildSpec: !Sub |
          version: 0.2
          env:
            variables:
              BASE_URL: &lt;Want to inject test app url here!!!&gt;
          phases:
            install:
              commands:
                - npm install
            build:
              commands:
                - npm run api-test
  </code></pre>