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.

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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠