2

我正在尝试将我的 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
4

1 回答 1

2

不幸的是,目前 CloudFormation 中的 CodeDeploy 仅支持 Lambda 平台上的蓝/绿部署,但是您的模板中的部署配置“CodeDeployDefault.AllAtOnce”适用于 EC2 平台。

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

作为一种解决方法,我建议您查看这篇博客文章和相关示例,了解如何使用 CodeDeploy [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

于 2020-02-05T11:36:49.920 回答