2

I'm trying to link my LoadBalancer and TargetGroup with DeploymentGroup, when I run the template it says " Property LoadBalancerInfo cannot be specified." here is snapshot of my template. is my template correct ?

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
Hector
  • 45
  • 7

1 Answers1

3

Unfortunately, at the moment CodeDeploy in CloudFormation only supports Blue/Green deployments on the Lambda platform however the deployment config "CodeDeployDefault.AllAtOnce" in your template is for the EC2 platform.

The reason the EC2 platform is not yet supported in CloudFormation is because Blue/Green CodeDeploy Deployments are fundamentally at odds with the resource management performed by CloudFormation. At its core, the Blue/Green feature within CodeDeploy will spin up Auto Scaling Groups on behalf of the customer by cloning existing ASGs and once the deployment is complete and stabilized it will delete the source ASG. This sort of out-of-band creation/deletion is something that fundamentally goes against the core function of CloudFormation where all resource operations originate from CloudFormation itself.

As a work around I recommend that you take a look at this blog post and associated example on how to setup Blue/Green Deployments with 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

shariqmaws
  • 8,152
  • 1
  • 16
  • 35
  • thank you @shariqmaws. I find it a bit weird because when we do it manually it allows us to choose BLUE/GREEN deployment type – Hector Feb 12 '20 at 01:39