如何引用`AWS::CodeDeploy::DeploymentGroup::LoadBalancerInfo?`

How to reference `AWS::CodeDeploy::DeploymentGroup::LoadBalancerInfo?`

我正在尝试 link 我的 LoadBalancer 和 TargetGroup 与 DeploymentGroup,当我 运行 模板时它说“无法指定 属性 LoadBalancerInfo。”这是我的模板的快照。我的模板正确吗?

EC2TargetGroup:
 Type: AWS::ElasticLoadBalancingV2::TargetGroup
 Properties:
   HealthCheckIntervalSeconds: 30
   HealthCheckProtocol: HTTP
   HealthCheckTimeoutSeconds: 15
   HealthyThresholdCount: 5
   Matcher:
     HttpCode: '200'
   Name: !Ref EC2TargetGroupName
   Port: 80
   Protocol: HTTP
   TargetGroupAttributes:
   - Key: deregistration_delay.timeout_seconds
     Value: '20'
   UnhealthyThresholdCount: 3
   VpcId: !Ref VPC

ApplicationLoadBalancer:
 Type: AWS::ElasticLoadBalancingV2::LoadBalancer
 Properties:
   Scheme: internet-facing
   SecurityGroups:
   - Ref: ELBSecurityGroup
   Subnets: !Ref Subnets

myAutoScalingGroup:
 Type: AWS::AutoScaling::AutoScalingGroup
 Properties:
  AutoScalingGroupName: !Ref ScalingGroupName
  MinSize: "1"
  MaxSize: !Ref MaxSize
  HealthCheckGracePeriod: 300
  LaunchTemplate:
    LaunchTemplateId: !Ref launchTemplate
    Version: !GetAtt launchTemplate.LatestVersionNumber

MyDeploymentGroup:
 Type: AWS::CodeDeploy::DeploymentGroup
 Properties:
  ApplicationName: !Ref ApplicationName
  DeploymentConfigName: CodeDeployDefault.AllAtOnce
  ServiceRoleArn: !GetAtt [PipelineRole, Arn]
  LoadBalancerInfo:
    TargetGroupInfoList:
      - Name: !Ref EC2TargetGroupName ############  ERROR ######
  DeploymentStyle:
    DeploymentType: BLUE_GREEN
    DeploymentOption: WITH_TRAFFIC_CONTROL

遗憾的是,目前 CloudFormation 中的 CodeDeploy 仅支持 Blue/Green Lambda 平台上的部署,但是您模板中的部署配置 "CodeDeployDefault.AllAtOnce" 适用于 EC2 平台。

CloudFormation 尚不支持 EC2 平台的原因是 Blue/GreenCodeDeploy 部署从根本上与 CloudFormation 执行的资源管理不一致。其核心是,CodeDeploy 中的 Blue/Green 功能将通过克隆现有 ASG 代表客户启动 Auto Scaling 组,一旦部署完成并稳定下来,它将删除源 ASG。这种带外 creation/deletion 从根本上违背了 CloudFormation 的核心功能,其中所有资源操作都源自 CloudFormation 本身。

作为解决方法,我建议您查看此博客 post 和相关示例,了解如何使用 CodeDeploy Blue/Green 部署 [1、2]。

[1] https://aws.amazon.com/blogs/devops/performing-bluegreen-deployments-with-aws-codedeploy-and-auto-scaling-groups/

[2] https://github.com/awslabs/codedeploy-blue-green