AWS CodePipeline: Get CloudFormation outputs in CodeBuild

冷暖自知 提交于 2019-12-11 08:53:30

问题


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:


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.



来源:https://stackoverflow.com/questions/51983901/aws-codepipeline-get-cloudformation-outputs-in-codebuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!