Skip to content

Commit

Permalink
feat(aws-ecs-patterns): adding support for custom HealthCheck while c…
Browse files Browse the repository at this point in the history
…reating QueueProcessingFargateService (aws#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 aws#15636

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
VarshaVid authored and TikiTDO committed Feb 21, 2022
1 parent e703ca3 commit 2e7be05
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
20 changes: 20 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,26 @@ const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateServ
});
```

### Set a custom container-level Healthcheck for QueueProcessingFargateService

```ts
declare const vpc: ec2.Vpc;
declare const securityGroup: ec2.SecurityGroup;
const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateService(this, 'Service', {
vpc,
memoryLimitMiB: 512,
image: ecs.ContainerImage.fromRegistry('test'),
healthCheck: {
command: [ "CMD-SHELL", "curl -f http://localhost/ || exit 1" ],
// the properties below are optional
interval: Duration.minutes(30),
retries: 123,
startPeriod: Duration.minutes(30),
timeout: Duration.minutes(30),
},
});
```

### Set capacityProviderStrategies for QueueProcessingEc2Service

```ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import { FargatePlatformVersion, FargateService, FargateTaskDefinition } from '@aws-cdk/aws-ecs';
import { FargatePlatformVersion, FargateService, FargateTaskDefinition, HealthCheck } from '@aws-cdk/aws-ecs';
import * as cxapi from '@aws-cdk/cx-api';
import { Construct } from 'constructs';
import { QueueProcessingServiceBase, QueueProcessingServiceBaseProps } from '../base/queue-processing-service-base';
Expand Down Expand Up @@ -69,6 +69,13 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
*/
readonly containerName?: string;

/**
* The health check command and associated configuration parameters for the container.
*
* @default - Health check configuration from container.
*/
readonly healthCheck?: HealthCheck;

/**
* The subnets to associate with the service.
*
Expand Down Expand Up @@ -127,6 +134,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
environment: this.environment,
secrets: this.secrets,
logging: this.logDriver,
healthCheck: props.healthCheck,
});

// The desiredCount should be removed from the fargate service when the feature flag is removed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@
}
],
"Essential": true,
"HealthCheck": {
"Command": [
"CMD-SHELL",
"curl -f http://localhost/ || exit 1"
],
"Interval": 720,
"Retries": 34,
"Timeout": 5
},
"Image": {
"Fn::Join": [
"",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import { App, Stack } from '@aws-cdk/core';
import { App, Stack, Duration } from '@aws-cdk/core';

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

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

app.synth();

0 comments on commit 2e7be05

Please sign in to comment.