Skip to content

Commit 7b968c9

Browse files
committed
feat: support healthCheckGracePeriod in QueueProcessingFargateService
Resolves #34220
1 parent e7a6e14 commit 7b968c9

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Construct } from 'constructs';
22
import * as ec2 from '../../../aws-ec2';
33
import { FargateService, FargateTaskDefinition, HealthCheck } from '../../../aws-ecs';
4-
import { FeatureFlags } from '../../../core';
4+
import { FeatureFlags, Duration } from '../../../core';
55
import * as cxapi from '../../../cx-api';
66
import { FargateServiceBaseProps } from '../base/fargate-service-base';
77
import { QueueProcessingServiceBase, QueueProcessingServiceBaseProps } from '../base/queue-processing-service-base';
@@ -47,6 +47,14 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
4747
* @default false
4848
*/
4949
readonly assignPublicIp?: boolean;
50+
51+
/**
52+
* The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy
53+
* Elastic Load Balancing target health checks after a task has first started.
54+
*
55+
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
56+
*/
57+
readonly healthCheckGracePeriod?: Duration;
5058
}
5159

5260
/**
@@ -117,6 +125,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
117125
circuitBreaker: props.circuitBreaker,
118126
capacityProviderStrategies: props.capacityProviderStrategies,
119127
enableExecuteCommand: props.enableExecuteCommand,
128+
healthCheckGracePeriod: props.healthCheckGracePeriod,
120129
});
121130

122131
this.configureAutoscalingForService(this.service);

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

+21
Original file line numberDiff line numberDiff line change
@@ -1005,3 +1005,24 @@ test('test Fargate queue worker service construct - with no taskDefinition or im
10051005
}).toThrow(new Error('You must specify one of: taskDefinition or image'));
10061006
});
10071007

1008+
test('test Fargate queue worker service construct - with healthCheckGracePeriod', () => {
1009+
// GIVEN
1010+
const stack = new cdk.Stack();
1011+
const vpc = new ec2.Vpc(stack, 'VPC');
1012+
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
1013+
const queue = new sqs.Queue(stack, 'Queue');
1014+
1015+
// WHEN
1016+
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
1017+
cluster,
1018+
queue,
1019+
image: ecs.ContainerImage.fromRegistry('test'),
1020+
healthCheckGracePeriod: cdk.Duration.seconds(120),
1021+
});
1022+
1023+
// THEN
1024+
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
1025+
HealthCheckGracePeriodSeconds: 120,
1026+
});
1027+
});
1028+

0 commit comments

Comments
 (0)