2
votes

I'm learning some DevOps techniques using AWS CodePipeline (Cloudformation and CodeBuild).

My (simplified) pipeline is this:

  1. Push to github repo triggers pipeline
  2. CloudFormation builds/updates backend infrastructure
  3. CodeBuild does some additional work

At the moment, CloudFormation outputs the following:

Outputs:
  RestApiId:
    Value: !Ref ApiGateway
    Description: 'API Id'

Question: How can I get the ApiGateway ID in CloudBuild?

1

1 Answers

3
votes

According to: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-parameter-override-functions.html

You can specify CodePipeline step like this (from documentation):

- Name: CreateTestStackA
  Actions:
    - Name: CloudFormationCreate
      ActionTypeId:
        Category: Deploy
        Owner: AWS
        Provider: CloudFormation
        Version: '1'
      Configuration:
        ActionMode: CREATE_UPDATE
        Capabilities: CAPABILITY_IAM
        OutputFileName: TestOutput.json
        RoleArn: !GetAtt [CFNRole, Arn]
        StackName: StackA
        TemplateConfiguration: TemplateSource::test-configuration.json
        TemplatePath: TemplateSource::teststackA.yaml
      InputArtifacts:
        - Name: TemplateSourceA
      OutputArtifacts:
        - Name: StackAOutput
      RunOrder: '1'

So in Configuration you need to add OutputFileName parameter and specify output artifact name. Then you can use that artifact as an input to CodeBuild. In output file (TestOutput.json) you will have a dictionary where key is output name and value is output value.