Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-ecs-patterns): adding support for custom HealthCheck while creating QueueProcessingFargateService #18219

Merged
merged 9 commits into from
Jan 25, 2022
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();