根据 CloudFormation 条件有条件地创建 CodePipeline 操作

Conditionally create CodePipeline actions based on CloudFormation conditions

使用条件为 CodePipeline 启用/禁用 CloudFormation 部分:

这会在构建暂存并通过 Runscope 测试后创建一个手动通知操作:

- InputArtifacts: []
      Name: !Join ["",[!Ref GitHubRepository, "-prd-approval"]]
      ActionTypeId:
        Category: Approval
        Owner: AWS
        Version: '1'
        Provider: Manual
      OutputArtifacts: []
      Configuration:
        NotificationArn: !GetAtt ["SNSApprovalNotification", "Outputs.SNSTopicArn"]
        ExternalEntityLink: OutputTestUrl
      RunOrder: 3

如何 enable/disable 这与具有条件的其他 CloudFormation 资源一样:。

操作步骤无法识别条件:参数

我可以制作整个管道代码的 2 个副本,一个有,一个没有,然后切换我创建的管道,但似乎应该有更好的方法。

您应该能够通过有条件地插入 AWS::CodePipeline::Pipeline Resource's Action into the Actions list using the Fn::If Intrinsic Function referencing your Conditions element, returning the Action when the Condition is true and AWS::NoValue(删除 属性,在本例中是从列表中删除该项目)来完成此操作:

- !If
  - IsProdCondition
  - InputArtifacts: []
    Name: !Join ["",[!Ref GitHubRepository, "-prd-approval"]]
    ActionTypeId:
      Category: Approval
      Owner: AWS
      Version: '1'
      Provider: Manual
    OutputArtifacts: []
    Configuration:
      NotificationArn: !GetAtt ["SNSApprovalNotification", "Outputs.SNSTopicArn"]
      ExternalEntityLink: OutputTestUrl
    RunOrder: 3
  - !Ref AWS::NoValue