AWS ECS Service and How to create a Code Deploy Deployment Group using Cloudformation or CLI

Viewed 19

I'm trying to create a deployment group for an AWS ECS deployment

I'm following the instruction that I found here: https://docs.aws.amazon.com/codedeploy/latest/userguide/deployment-groups-create-ecs.html

The only issue is the example is done through the console and I'd prefer to do it either with Cloudformation or the CLI.

So, I decided to create my template. This is my AWS::CodeDeploy::DeploymentGroup

  CDDeploymentGroup:
    Type: AWS::CodeDeploy::DeploymentGroup
    Properties: 
      ApplicationName:
        Ref: CDApp
      DeploymentConfigName: CodeDeployDefault.LambdaCanary10Percent5Minutes 
      DeploymentStyle: 
        DeploymentType: BLUE_GREEN
        DeploymentOption: WITH_TRAFFIC_CONTROL 
      LoadBalancerInfo:
        ElbInfoList: 
          - Name: !Ref LoadBalancer
        TargetGroupPairInfoList:
          - ProdTrafficRoute:
              ListenerArns: 
                - !Ref LoadBalancerListener1
          - TestTrafficRoute:
              ListenerArns:
                - !Ref LoadBalancerListener1
        TargetGroupInfoList:
          - Name: !Ref LoadBalancerTG1
          - Name: !RefLoadBalancerTG2          
      ServiceRoleArn: 
        Fn::GetAtt: [ CodeDeployRole, Arn ]

When I deploy this template, Cloudformation fails with the following error:

my-cluster UPDATE_ROLLBACK_IN_PROGRESS. The following resource(s) failed to create: [CDDeploymentGroup, Service2].

Service2 CREATE_FAILED. Resource creation cancelled

CDDeploymentGroup CREATE_FAILED Property LoadBalancerInfo cannot be specified.

I searched for this error and I found that CodeDeploy in Cloudformation only supports Blue/Green deployments for Lambda.

However, I was able to follow the previous document and make it work through the console. If I can make it work using the console I should be able to make it work at least with the cli, correct?

How can I set up the Deployment Group using Cloudformation or the CLI? This is turning me crazy.

Thanks.

1 Answers

Amazon ECS blue/green deployments through CodeDeploy do not use the AWS::CodeDeploy::DeploymentGroup resource. To perform Amazon ECS blue/green deployments, use the AWS::CodeDeploy::BlueGreen hook. See Perform Amazon ECS blue/green deployments through CodeDeploy using AWS CloudFormation for more information.

Ref : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentgroup.html#cfn-codedeploy-deploymentgroup-loadbalancerinfo

Above article points to this article for more details : https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html

Apparently, you'll need to us AWS::CodeDeploy::BlueGreen hook in your CloudFormation template for ECS b/g deployments and not AWS::CodeDeploy::DeploymentGroup resource, which is applicable only for Lambda b/g deployments.

Related