skip to Main Content

I am deploying a service on aws using an ApplicationLoadBalancedEc2Service.

Sometimes while doing some testing, I deploy a configuration that results in errors. The problem is that instead of canceling the deployment, the cdk just hangs for hours. The reason is that AWS tries to keep spinning up a task (which fails due to my wrong configuration).

Right now I have to set the task number to 0 through the AWS console. This will cause to successfully complete the deployment and allow me to spin a new version.

Is there a way to cancel the deployment and just rollback after X amount of failed tasks?

2

Answers


  1. One way is to configure CodeDeploy to roll back the service to its previous version if the new deployment fails. This won’t "cancel the CDK deployment", but will stabilize the service.

    Another way is to add a Custom Resource with an asynchronous provider to poll the ECS service status, signaling CloudFormation if your success condition is not met. This will revert the CDK deployment itself.

    Login or Signup to reply.
  2. You’re looking for the Circuit Breaker feature:

    declare const cluster: ecs.Cluster;
    const loadBalancedEcsService = new ecsPatterns.ApplicationLoadBalancedEc2Service(this, 'Service', {
      cluster,
      memoryLimitMiB: 1024,
      taskImageOptions: {
        image: ecs.ContainerImage.fromRegistry('test'),
      },
      desiredCount: 2,
      circuitBreaker: { rollback: true }
    });
    

    It will give your deploy between 10 and 200 tries (0.5 times your desired task count, with these min/max values), before to cancel your deploy. The rollback argument allows you to re-launch tasks with the previous task definition.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search