问题
I'm learning some DevOps techniques using AWS CodePipeline (Cloudformation and CodeBuild).
My (simplified) pipeline is this:
- Push to github repo triggers pipeline
- CloudFormation builds/updates backend infrastructure
- 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