Search code examples
amazon-web-servicesamazon-ec2devopsaws-code-deploy

AWS CodeDeploy - Property LoadBalancerInfo cannot be specified


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.


Solution

  • You can only use Blue/Green with the Lambda compute platform.

    From the CloudFormation docs:

    AWS CloudFormation supports blue/green deployments on the AWS Lambda compute platform only.