Skip to content

feat: support healthCheckGracePeriod in QueueProcessingFargateService #34231

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as path from 'path';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { App, Duration, Stack } from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { QueueProcessingFargateService } from 'aws-cdk-lib/aws-ecs-patterns';

const app = new App();
const stack = new Stack(app, 'aws-ecs-patterns-queue-grace-period');
const vpc = new ec2.Vpc(stack, 'VPC', {
restrictDefaultSecurityGroup: false,
maxAzs: 2,
});

new QueueProcessingFargateService(stack, 'QueueProcessingService', {
vpc,
memoryLimitMiB: 512,
image: new ecs.AssetImage(path.join(__dirname, '..', 'sqs-reader')),
minScalingCapacity: 0,
healthCheckGracePeriod: Duration.seconds(120),
});

new integ.IntegTest(app, 'queueProcessingFargateServiceGracePeriodTest', {
testCases: [stack],
});

app.synth();
13 changes: 13 additions & 0 deletions packages/aws-cdk-lib/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,19 @@ const networkLoadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFar
});
```

### Set healthCheckGracePeriod for QueueProcessingFargateService

```ts
declare const vpc: ec2.Vpc;
const queueProcessingFargateService = new ecsPatterns.QueueProcessingFargateService(this, 'Service', {
vpc,
memoryLimitMiB: 512,
image: ecs.ContainerImage.fromRegistry('test'),
minHealthyPercent: 100,
healthCheckGracePeriod: Duration.seconds(120),
});
```

### Set securityGroups for NetworkLoadBalancedFargateService

```ts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Construct } from 'constructs';
import * as ec2 from '../../../aws-ec2';
import { FargateService, FargateTaskDefinition, HealthCheck } from '../../../aws-ecs';
import { FeatureFlags } from '../../../core';
import { FeatureFlags, Duration } from '../../../core';
import * as cxapi from '../../../cx-api';
import { FargateServiceBaseProps } from '../base/fargate-service-base';
import { QueueProcessingServiceBase, QueueProcessingServiceBaseProps } from '../base/queue-processing-service-base';
Expand Down Expand Up @@ -47,6 +47,14 @@ export interface QueueProcessingFargateServiceProps extends QueueProcessingServi
* @default false
*/
readonly assignPublicIp?: boolean;

/**
* The period of time, in seconds, that the Amazon ECS service scheduler ignores unhealthy
* Elastic Load Balancing target health checks after a task has first started.
*
* @default - defaults to 60 seconds if at least one load balancer is in-use and it is not already set
*/
readonly healthCheckGracePeriod?: Duration;
}

/**
Expand Down Expand Up @@ -117,6 +125,7 @@ export class QueueProcessingFargateService extends QueueProcessingServiceBase {
circuitBreaker: props.circuitBreaker,
capacityProviderStrategies: props.capacityProviderStrategies,
enableExecuteCommand: props.enableExecuteCommand,
healthCheckGracePeriod: props.healthCheckGracePeriod,
});

this.configureAutoscalingForService(this.service);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,24 @@ test('test Fargate queue worker service construct - with no taskDefinition or im
}).toThrow(new Error('You must specify one of: taskDefinition or image'));
});

test('test Fargate queue worker service construct - with healthCheckGracePeriod', () => {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'VPC');
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc });
const queue = new sqs.Queue(stack, 'Queue');

// WHEN
new ecsPatterns.QueueProcessingFargateService(stack, 'Service', {
cluster,
queue,
image: ecs.ContainerImage.fromRegistry('test'),
healthCheckGracePeriod: cdk.Duration.seconds(120),
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ECS::Service', {
HealthCheckGracePeriodSeconds: 120,
});
});

Loading