Skip to content

Commit 0ca81a1

Browse files
authored
feat(aws-ecs-patterns): adding support for custom HealthCheck while creating QueueProcessingFargateService (#18219)
The `QueueProcessingFargateService` construct internally creates a service Container with the default healthcheck that cannot currently be overriden by the user. This change allows users to optionally provide a custom healthcheck that can be passed on to the internal ECS container definition. fixes #15636 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 67bf448 commit 0ca81a1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Diff for: packages/@aws-cdk/aws-ecs-patterns/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,26 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ
544544
});
545545
```
546546

547+
### Set a custom container-level Healthcheck for QueueProcessingFargateService
548+
549+
```ts
550+
declare const vpc: ec2.Vpc;
551+
declare const securityGroup: ec2.SecurityGroup;
552+
const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateService(this, 'Service', {
553+
vpc,
554+
memoryLimitMiB: 512,
555+
image: ecs.ContainerImage.fromRegistry('test'),
556+
healthCheck: {
557+
command: [ "CMD-SHELL", "curl -f http://localhost/ || exit 1" ],
558+
// the properties below are optional
559+
interval: Duration.minutes(30),
560+
retries: 123,
561+
startPeriod: Duration.minutes(30),
562+
timeout: Duration.minutes(30),
563+
},
564+
});
565+
```
566+
547567
### Set capacityProviderStrategies for QueueProcessingEc2Service
548568

549569
```ts

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ec2 from '@aws-cdk/aws-ec2';
2-
import { FargatePlatformVersion, FargateService, FargateTaskDefinition } from '@aws-cdk/aws-ecs';
2+
import { FargatePlatformVersion, FargateService, FargateTaskDefinition, HealthCheck } from '@aws-cdk/aws-ecs';
33
import * as cxapi from '@aws-cdk/cx-api';
44
import { Construct } from 'constructs';
55
import { QueueProcessingServiceBase, QueueProcessingServiceBaseProps } from '../base/queue-processing-service-base';
@@ -69,6 +69,13 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
6969
*/
7070
readonly containerName?: string;
7171

72+
/**
73+
* The health check command and associated configuration parameters for the container.
74+
*
75+
* @default - Health check configuration from container.
76+
*/
77+
readonly healthCheck?: HealthCheck;
78+
7279
/**
7380
* The subnets to associate with the service.
7481
*
@@ -127,6 +134,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
127134
environment: this.environment,
128135
secrets: this.secrets,
129136
logging: this.logDriver,
137+
healthCheck: props.healthCheck,
130138
});
131139

132140
// The desiredCount should be removed from the fargate service when the feature flag is removed.

Diff for: packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.queue-processing-fargate-service-public.expected.json

+9
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,15 @@
604604
}
605605
],
606606
"Essential": true,
607+
"HealthCheck": {
608+
"Command": [
609+
"CMD-SHELL",
610+
"curl -f http://localhost/ || exit 1"
611+
],
612+
"Interval": 720,
613+
"Retries": 34,
614+
"Timeout": 5
615+
},
607616
"Image": {
608617
"Fn::Join": [
609618
"",

Diff for: packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.queue-processing-fargate-service-public.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as path from 'path';
22
import * as ec2 from '@aws-cdk/aws-ec2';
33
import * as ecs from '@aws-cdk/aws-ecs';
4-
import { App, Stack } from '@aws-cdk/core';
4+
import { App, Stack, Duration } from '@aws-cdk/core';
55

66
import { QueueProcessingFargateService } from '../../lib';
77

@@ -14,6 +14,11 @@ new QueueProcessingFargateService(stack, 'PublicQueueService', {
1414
memoryLimitMiB: 512,
1515
image: new ecs.AssetImage(path.join(__dirname, '..', 'sqs-reader')),
1616
assignPublicIp: true,
17+
healthCheck: {
18+
command: ['CMD-SHELL', 'curl -f http://localhost/ || exit 1'],
19+
interval: Duration.minutes(12),
20+
retries: 34,
21+
},
1722
});
1823

1924
app.synth();

0 commit comments

Comments
 (0)