Skip to content

Commit a109984

Browse files
author
Abdul Kader Maliyakkal
committed
Add ECS deployment circuit breaker support to higher-level constructs
1 parent cbed348 commit a109984

14 files changed

+191
-4
lines changed

packages/@aws-cdk/aws-ecs-patterns/README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,28 @@ const loadBalancedFargateService = new ApplicationLoadBalancedFargateService(sta
394394
});
395395
```
396396

397+
### Deployment circuit breaker and rollback
398+
399+
Amazon ECS [deployment circuit breaker](https://aws.amazon.com/tw/blogs/containers/announcing-amazon-ecs-deployment-circuit-breaker/)
400+
automatically rolls back unhealthy service deployments without the need for manual intervention. Use `circuitBreaker` to enable
401+
deployment circuit breaker and optionally enable `rollback` for automatic rollback. See [Using the deployment circuit breaker](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/deployment-type-ecs.html)
402+
for more details.
403+
404+
```ts
405+
const service = new ApplicationLoadBalancedFargateService(stack, 'Service', {
406+
cluster,
407+
memoryLimitMiB: 1024,
408+
desiredCount: 1,
409+
cpu: 512,
410+
taskImageOptions: {
411+
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
412+
},
413+
deploymentController: {
414+
type: ecs.DeploymentControllerType.ECS,
415+
},
416+
circuitBreaker: { rollback: true },
417+
});
418+
```
397419

398420
### Set deployment configuration on QueueProcessingService
399421

@@ -469,7 +491,7 @@ const scheduledFargateTask = new ScheduledFargateTask(stack, 'ScheduledFargateTa
469491

470492
### Use the REMOVE_DEFAULT_DESIRED_COUNT feature flag
471493

472-
The REMOVE_DEFAULT_DESIRED_COUNT feature flag is used to override the default desiredCount that is autogenerated by the CDK. This will set the desiredCount of any service created by any of the following constructs to be undefined.
494+
The REMOVE_DEFAULT_DESIRED_COUNT feature flag is used to override the default desiredCount that is autogenerated by the CDK. This will set the desiredCount of any service created by any of the following constructs to be undefined.
473495

474496
* ApplicationLoadBalancedEc2Service
475497
* ApplicationLoadBalancedFargateService

packages/@aws-cdk/aws-ecs-patterns/lib/base/application-load-balanced-service-base.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Certificate, CertificateValidation, ICertificate } from '@aws-cdk/aws-certificatemanager';
22
import { IVpc } from '@aws-cdk/aws-ec2';
3-
import { AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
3+
import {
4+
AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, DeploymentCircuitBreaker,
5+
ICluster, LogDriver, PropagatedTagSource, Secret,
6+
} from '@aws-cdk/aws-ecs';
47
import {
58
ApplicationListener, ApplicationLoadBalancer, ApplicationProtocol, ApplicationTargetGroup,
69
IApplicationLoadBalancer, ListenerCertificate, ListenerAction, AddApplicationTargetsProps,
@@ -226,6 +229,14 @@ export interface ApplicationLoadBalancedServiceBaseProps {
226229
* @default - Rolling update (ECS)
227230
*/
228231
readonly deploymentController?: DeploymentController;
232+
233+
/**
234+
* Whether to enable the deployment circuit breaker. If this property is defined, circuit breaker will be implicitly
235+
* enabled.
236+
* @default - disabled
237+
*/
238+
readonly circuitBreaker?: DeploymentCircuitBreaker;
239+
229240
}
230241

231242
export interface ApplicationLoadBalancedTaskImageOptions {

packages/@aws-cdk/aws-ecs-patterns/lib/base/network-load-balanced-service-base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { IVpc } from '@aws-cdk/aws-ec2';
2-
import { AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
2+
import {
3+
AwsLogDriver, BaseService, CloudMapOptions, Cluster, ContainerImage, DeploymentController, DeploymentCircuitBreaker,
4+
ICluster, LogDriver, PropagatedTagSource, Secret,
5+
} from '@aws-cdk/aws-ecs';
36
import { INetworkLoadBalancer, NetworkListener, NetworkLoadBalancer, NetworkTargetGroup } from '@aws-cdk/aws-elasticloadbalancingv2';
47
import { IRole } from '@aws-cdk/aws-iam';
58
import { ARecord, CnameRecord, IHostedZone, RecordTarget } from '@aws-cdk/aws-route53';
@@ -176,6 +179,13 @@ export interface NetworkLoadBalancedServiceBaseProps {
176179
* @default - Rolling update (ECS)
177180
*/
178181
readonly deploymentController?: DeploymentController;
182+
183+
/**
184+
* Whether to enable the deployment circuit breaker. If this property is defined, circuit breaker will be implicitly
185+
* enabled.
186+
* @default - disabled
187+
*/
188+
readonly circuitBreaker?: DeploymentCircuitBreaker;
179189
}
180190

181191
export interface NetworkLoadBalancedTaskImageOptions {

packages/@aws-cdk/aws-ecs-patterns/lib/base/queue-processing-service-base.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { ScalingInterval } from '@aws-cdk/aws-applicationautoscaling';
22
import { IVpc } from '@aws-cdk/aws-ec2';
3-
import { AwsLogDriver, BaseService, Cluster, ContainerImage, DeploymentController, ICluster, LogDriver, PropagatedTagSource, Secret } from '@aws-cdk/aws-ecs';
3+
import {
4+
AwsLogDriver, BaseService, Cluster, ContainerImage, DeploymentController, DeploymentCircuitBreaker,
5+
ICluster, LogDriver, PropagatedTagSource, Secret,
6+
} from '@aws-cdk/aws-ecs';
47
import { IQueue, Queue } from '@aws-cdk/aws-sqs';
58
import { CfnOutput, Duration, Stack } from '@aws-cdk/core';
69
import * as cxapi from '@aws-cdk/cx-api';
@@ -189,6 +192,13 @@ export interface QueueProcessingServiceBaseProps {
189192
* @default - Rolling update (ECS)
190193
*/
191194
readonly deploymentController?: DeploymentController;
195+
196+
/**
197+
* Whether to enable the deployment circuit breaker. If this property is defined, circuit breaker will be implicitly
198+
* enabled.
199+
* @default - disabled
200+
*/
201+
readonly circuitBreaker?: DeploymentCircuitBreaker;
192202
}
193203

194204
/**

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/application-load-balanced-ecs-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export class ApplicationLoadBalancedEc2Service extends ApplicationLoadBalancedSe
133133
enableECSManagedTags: props.enableECSManagedTags,
134134
cloudMapOptions: props.cloudMapOptions,
135135
deploymentController: props.deploymentController,
136+
circuitBreaker: props.circuitBreaker,
136137
});
137138
this.addServiceAsTarget(this.service);
138139
}

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/network-load-balanced-ecs-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class NetworkLoadBalancedEc2Service extends NetworkLoadBalancedServiceBas
131131
enableECSManagedTags: props.enableECSManagedTags,
132132
cloudMapOptions: props.cloudMapOptions,
133133
deploymentController: props.deploymentController,
134+
circuitBreaker: props.circuitBreaker,
134135
});
135136
this.addServiceAsTarget(this.service);
136137
}

packages/@aws-cdk/aws-ecs-patterns/lib/ecs/queue-processing-ecs-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export class QueueProcessingEc2Service extends QueueProcessingServiceBase {
114114
propagateTags: props.propagateTags,
115115
enableECSManagedTags: props.enableECSManagedTags,
116116
deploymentController: props.deploymentController,
117+
circuitBreaker: props.circuitBreaker,
117118
});
118119

119120
this.configureAutoscalingForService(this.service);

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export class ApplicationLoadBalancedFargateService extends ApplicationLoadBalanc
170170
cloudMapOptions: props.cloudMapOptions,
171171
platformVersion: props.platformVersion,
172172
deploymentController: props.deploymentController,
173+
circuitBreaker: props.circuitBreaker,
173174
securityGroups: props.securityGroups,
174175
vpcSubnets: props.taskSubnets,
175176
});

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/network-load-balanced-fargate-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
157157
cloudMapOptions: props.cloudMapOptions,
158158
platformVersion: props.platformVersion,
159159
deploymentController: props.deploymentController,
160+
circuitBreaker: props.circuitBreaker,
160161
vpcSubnets: props.taskSubnets,
161162
});
162163
this.addServiceAsTarget(this.service);

packages/@aws-cdk/aws-ecs-patterns/lib/fargate/queue-processing-fargate-service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
148148
securityGroups: props.securityGroups,
149149
vpcSubnets: props.taskSubnets,
150150
assignPublicIp: props.assignPublicIp,
151+
circuitBreaker: props.circuitBreaker,
151152
});
152153

153154
this.configureAutoscalingForService(this.service);

0 commit comments

Comments
 (0)