AWS CodeDeploy - Property LoadBalancerInfo cannot be specified

1

I am creating a code deploy deployment group with CloudFormation. The code deploy is one of Blue/Green to deploy EC2 instances.

I am having an issue when i declare my Target Group to be used - CloudFormation requires the name of the Target Group where the instances will be deregistered from AWS Documentation.

I have the CloudFormation Template deploying the - Target Group, ALB, CodeDeploy Application and CodeDeploy DeploymentGroup so you will see - !Refs and !GetAtt intrinsic functions

But getting this error on CloudFormation - 'Property LoadBalancerInfo cannot be specified'

ServiceCodeDeployApplication:
    DependsOn:
      - 'ServiceGreenListenerRule'
    Type: AWS::CodeDeploy::Application
    Properties:
      ApplicationName: !Sub "App-${Project}-${Service}"
      ComputePlatform: Server

  ServiceCodeDeployGroupApplication:
      Type: AWS::CodeDeploy::DeploymentGroup
      Properties:
        ApplicationName: !Ref ServiceCodeDeployApplication
        AutoRollbackConfiguration:
          Enabled: true
          Events:
            - DEPLOYMENT_FAILURE
            - DEPLOYMENT_STOP_ON_REQUEST
        BlueGreenDeploymentConfiguration:
          DeploymentReadyOption:
            ActionOnTimeout: CONTINUE_DEPLOYMENT
            WaitTimeInMinutes: 0
          TerminateBlueInstancesOnDeploymentSuccess:
            Action: TERMINATE
            TerminationWaitTimeInMinutes: 10
        DeploymentGroupName: !Sub 'DgpECS-${Project}-${Service}'
        DeploymentStyle:
          DeploymentOption: WITH_TRAFFIC_CONTROL
          DeploymentType: BLUE_GREEN
        Ec2TagSet:
          Ec2TagSetList:
            - Ec2TagGroup:
              - Key: 'environment'
                Type: 'KEY_AND_VALUE'
                Value: 'production'
        LoadBalancerInfo:
          TargetGroupInfoList:
            - Name: !GetAtt ServiceTargetGroup.TargetGroupName
        ServiceRoleArn: arn:aws:iam::xxxxxxx:role/AWSCodeDeployRole

Creating it manually from console you get to choose the Target Group by enabling Load Balancing option.

I tried to have the name in static format and have it by using !GetAtt Intrinsic Function, see the code above, but fails in both.

I have seen this solution to a CodeDeploy DeploymentGroup without Blue/Green that works.

Only way my templates deploy is when i make the following changes:

  • In AWS::CodeDeploy::Application Resource - remove the ComputePlatform: Server line

  • In AWS::CodeDeploy::DeploymentGroup Resource - remove the blue/green - DeploymentType and BlueGreenDeploymentConfiguration block.

Working Code Excerpt -

ServiceCodeDeployApplication:
    DependsOn:
      - 'ServiceGreenListenerRule'
    Type: AWS::CodeDeploy::Application
    Properties:
      ApplicationName: !Sub "App-${Project}-${Service}"

  ServiceCodeDeployGroupApplication:
      Type: AWS::CodeDeploy::DeploymentGroup
      Properties:
        ApplicationName: !Ref ServiceCodeDeployApplication
        AutoRollbackConfiguration:
          Enabled: true
          Events:
            - DEPLOYMENT_FAILURE
            - DEPLOYMENT_STOP_ON_REQUEST
        DeploymentGroupName: !Sub 'DgpECS-${Project}-${Service}'
        DeploymentStyle:
          DeploymentOption: WITH_TRAFFIC_CONTROL
        Ec2TagSet:
          Ec2TagSetList:
            - Ec2TagGroup:
              - Key: 'environment'
                Type: 'KEY_AND_VALUE'
                Value: 'production'
        LoadBalancerInfo:
          TargetGroupInfoList:
            - Name: !GetAtt ServiceTargetGroup.TargetGroupName
        ServiceRoleArn: arn:aws:iam::xxxxxx:role/AWSCodeDeployRole

Any pointers would be welcomed.

profile picture
已提问 10 个月前271 查看次数
2 回答
1
已接受的回答

As described in this document, Blue/Green cannot be used when deploying to EC2 when setting up CodeDeploy in CloudFormation.
LoadBalancerInfo cannot be set together when DeploymentType is set to Blue/Green.
https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentgroup.html#cfn-codedeploy-deploymentgroup-deploymentstyle

If you specify this property with a blue/green deployment type, don't specify the AutoScalingGroups, LoadBalancerInfo, or Deployment properties.
For blue/green deployments, AWS CloudFormation supports deployments on Lambda compute platforms only. You can perform Amazon ECS blue/green deployments using AWS::CodeDeploy::BlueGreen hook. See Perform Amazon ECS blue/green deployments through CodeDeploy using AWS CloudFormation for more information.

profile picture
专家
已回答 10 个月前
profile pictureAWS
专家
已审核 10 个月前
  • Thanks for pointing this out, i missed it.

0

This is a rediculous problem to have and CFN should absolutely support setting the LoadBalancerInfo when using Blue/Green deployments. I found a "workaround" but it's a 2-step process.

Steps:

  1. Define your non-blue/green CodeDeploy DeploymentGroup with the proper LoadBalancerInfo
  2. Deploy to CFN
  3. Change the CodeDeploy DeploymentGroup to blue/green
  4. Remove (comment out) the LoadBalancerInfo
  5. Deploy to CFN
  6. Discover that CFN doesn't reset the old LoadBalancers and just keeps using the existing ones
  7. Done

As long as you don't have to change the LoadBalancers this should work. At least until the CodeDeploy team updates their CFN resources properly.

profile picture
RNHurt
已回答 7 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则