Skip to content

Commit

Permalink
feat(ecs): pass healthy percent & deregistraiton delay params in L3 c…
Browse files Browse the repository at this point in the history
…onstruct
  • Loading branch information
cheruvian committed Jan 9, 2024
1 parent ca91626 commit 15553df
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ export interface ApplicationMultipleTargetGroupsServiceBaseProps {
* @default - false
*/
readonly enableExecuteCommand?: boolean;

/**
* The minimum number of tasks, specified as a percentage of
* the Amazon ECS service's DesiredCount value, that must
* continue to run and remain healthy during a deployment.
*
* @default - 0 if daemon, otherwise 50
*/
readonly minHealthyPercent?: number;
}

/**
Expand Down Expand Up @@ -268,6 +277,15 @@ export interface ApplicationTargetProps {
* @default No path condition
*/
readonly pathPattern?: string;

/**
* The amount of time for Elastic Load Balancing to wait before deregistering a target.
*
* The range is 0-3600 seconds.
*
* @default 300
*/
readonly deregistrationDelay?: Duration;
}

/**
Expand Down Expand Up @@ -516,6 +534,7 @@ export abstract class ApplicationMultipleTargetGroupsServiceBase extends Constru
}),
],
conditions,
deregistrationDelay: targetProps.deregistrationDelay,
priority: targetProps.priority,
});
this.targetGroups.push(targetGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ export interface NetworkMultipleTargetGroupsServiceBaseProps {
* @default - false
*/
readonly enableExecuteCommand?: boolean;

/**
* The minimum number of tasks, specified as a percentage of
* the Amazon ECS service's DesiredCount value, that must
* continue to run and remain healthy during a deployment.
*
* @default - 0 if daemon, otherwise 50
*/
readonly minHealthyPercent?: number;
}

/**
Expand Down Expand Up @@ -268,6 +277,15 @@ export interface NetworkTargetProps {
* @default - default listener (first added listener)
*/
readonly listener?: string;

/**
* The amount of time for Elastic Load Balancing to wait before deregistering a target.
*
* The range is 0-3600 seconds.
*
* @default 300
*/
readonly deregistrationDelay?: Duration;
}

/**
Expand Down Expand Up @@ -394,6 +412,7 @@ export abstract class NetworkMultipleTargetGroupsServiceBase extends Construct {
containerPort: targetProps.containerPort,
}),
],
deregistrationDelay: targetProps.deregistrationDelay,
});
this.targetGroups.push(targetGroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ export class ApplicationMultipleTargetGroupsEc2Service extends ApplicationMultip
enableExecuteCommand: props.enableExecuteCommand,
placementConstraints: props.placementConstraints,
placementStrategies: props.placementStrategies,
minHealthyPercent: props.minHealthyPercent,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class NetworkMultipleTargetGroupsEc2Service extends NetworkMultipleTarget
enableExecuteCommand: props.enableExecuteCommand,
placementConstraints: props.placementConstraints,
placementStrategies: props.placementStrategies,
minHealthyPercent: props.minHealthyPercent,
});
}
}
4 changes: 4 additions & 0 deletions packages/aws-cdk-lib/aws-ecs-patterns/test/ec2/l3s-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe('When Application Load Balancer', () => {
],
placementStrategies: [PlacementStrategy.spreadAcrossInstances(), PlacementStrategy.packedByCpu(), PlacementStrategy.randomly()],
placementConstraints: [PlacementConstraint.memberOf('attribute:ecs.instance-type =~ m5a.*')],
minHealthyPercent: 50,
});

// THEN
Expand Down Expand Up @@ -197,6 +198,7 @@ describe('When Application Load Balancer', () => {
ServiceName: 'myService',
PlacementConstraints: [{ Type: 'memberOf', Expression: 'attribute:ecs.instance-type =~ m5a.*' }],
PlacementStrategies: [{ Field: 'instanceId', Type: 'spread' }, { Field: 'CPU', Type: 'binpack' }, { Type: 'random' }],
DeploymentConfiguration: { MinimumHealthyPercent: 50 },
});

Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
Expand Down Expand Up @@ -1148,6 +1150,7 @@ describe('When Network Load Balancer', () => {
],
placementStrategies: [PlacementStrategy.spreadAcrossInstances(), PlacementStrategy.packedByCpu(), PlacementStrategy.randomly()],
placementConstraints: [PlacementConstraint.memberOf('attribute:ecs.instance-type =~ m5a.*')],
minHealthyPercent: 50,
});

// THEN
Expand Down Expand Up @@ -1178,6 +1181,7 @@ describe('When Network Load Balancer', () => {
ServiceName: 'myService',
PlacementConstraints: [{ Type: 'memberOf', Expression: 'attribute:ecs.instance-type =~ m5a.*' }],
PlacementStrategies: [{ Field: 'instanceId', Type: 'spread' }, { Field: 'CPU', Type: 'binpack' }, { Type: 'random' }],
DeploymentConfiguration: { MinimumHealthyPercent: 50 },
});

Template.fromStack(stack).hasResourceProperties('AWS::ECS::TaskDefinition', {
Expand Down

0 comments on commit 15553df

Please sign in to comment.