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(ecs-patterns): adding support for custom HealthCheck in NetworkLoadBalancedFargateService #21083

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ const loadBalancedFargateService = new ecsPatterns.NetworkLoadBalancedFargateSer
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
},
healthCheck: {
daschaa marked this conversation as resolved.
Show resolved Hide resolved
command: ['CMD-SHELL', 'wget localhost:5000'],
},
});
```

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SubnetSelection } 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 { FeatureFlags } from '@aws-cdk/core';
import * as cxapi from '@aws-cdk/cx-api';
import { Construct } from 'constructs';
Expand Down Expand Up @@ -85,6 +85,13 @@ export interface NetworkLoadBalancedFargateServiceProps extends NetworkLoadBalan
* @default Latest
*/
readonly platformVersion?: FargatePlatformVersion;

/**
* The health check command and associated configuration parameters for the container.
daschaa marked this conversation as resolved.
Show resolved Hide resolved
*
* @default - Health check configuration from container.
*/
readonly healthCheck?: HealthCheck;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this more, I'm not sure we should expose this on the top level props. For an ECS service there behind a load balancer there are two different types of health checks that you can use.

  1. ELB health checks (configured on the NLB in this case). The NLB will make a request to the service on a specific path/port and expect a certain response.
  2. Container health checks (what this PR exposes). The service itself can perform health checks against the running containers (in addition to the ELB health checks).

I'm not sure this is a common use case for services running behind an ELB. The other linked PR that implemented this for the QueueProcessing service makes more sense because it is a worker service that is not running behind an ELB so container health checks are the only type of health check available.

I think in the majority of cases the user wants to configure the ELB health check and exposing this at the top level (an not the elb health check) would lead to more confusion and users configuring container health checks when they don't need to.

cc @madeline-k for a second opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@corymhall Ok I think this makes sense. Maybe we should close this (and the linked issue) and come up with a solution if there is a real need for this. And even then explicitly document the consequences.

And I want to apologize for implementing this feature without really thinking about it. I will try to go more in-depth in a topic I will implement in the future.

}

/**
Expand Down Expand Up @@ -135,6 +142,7 @@ export class NetworkLoadBalancedFargateService extends NetworkLoadBalancedServic
environment: taskImageOptions.environment,
secrets: taskImageOptions.secrets,
dockerLabels: taskImageOptions.dockerLabels,
healthCheck: props.healthCheck,
});
container.addPortMappings({
containerPort: taskImageOptions.containerPort || 80,
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-ecs-patterns/test/fargate/integ.l3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ new ecsPatterns.NetworkLoadBalancedFargateService(stack, 'NLBFargateService', {
taskImageOptions: {
image: ecs.ContainerImage.fromRegistry('amazon/amazon-ecs-sample'),
},
healthCheck: {
command: ['some command'],
},
});

app.synth();
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "17.0.0",
"version": "20.0.0",
"files": {
"df69d2ecce2a4821319e5d7c7a82c2788b52a69dd46e19809ca9d208bf17231f": {
"5ad71626a2e88b8d545b41d9d9ac40a67383269e200e803c6f0568ea8d694f53": {
"source": {
"path": "aws-ecs-integ-lb-fargate.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "df69d2ecce2a4821319e5d7c7a82c2788b52a69dd46e19809ca9d208bf17231f.json",
"objectKey": "5ad71626a2e88b8d545b41d9d9ac40a67383269e200e803c6f0568ea8d694f53.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,15 @@
"ContainerDefinitions": [
{
"Essential": true,
"HealthCheck": {
"Command": [
"CMD-SHELL",
"some command"
],
"Interval": 30,
"Retries": 3,
"Timeout": 5
},
"Image": "amazon/amazon-ecs-sample",
"LogConfiguration": {
"LogDriver": "awslogs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"17.0.0"}
{"version":"20.0.0"}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"version": "18.0.0",
"version": "20.0.0",
"testCases": {
"aws-ecs-patterns/test/fargate/integ.l3": {
"fargate/integ.l3": {
"stacks": [
"aws-ecs-integ-lb-fargate"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "17.0.0",
"version": "20.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
Expand Down Expand Up @@ -282,7 +282,10 @@
"/aws-ecs-integ-lb-fargate/NLBFargateService/TaskDef/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "NLBFargateServiceTaskDefB836FA89"
"data": "NLBFargateServiceTaskDefB836FA89",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
]
}
],
"/aws-ecs-integ-lb-fargate/NLBFargateService/TaskDef/web/LogGroup/Resource": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"path": "Tree",
"constructInfo": {
"fqn": "constructs.Construct",
"version": "10.0.9"
"version": "10.1.33"
}
},
"aws-ecs-integ-lb-fargate": {
Expand Down Expand Up @@ -1418,6 +1418,15 @@
"Ref": "AWS::Region"
}
}
},
"healthCheck": {
"command": [
"CMD-SHELL",
"some command"
],
"interval": 30,
"retries": 3,
"timeout": 5
}
}
],
Expand Down