Skip to content
v2.278.0

HealthCheck Struct ​

Properties for configuring a health check.

Example ​

ts
declare const cluster: ecs.Cluster;
const loadBalancedFargateService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, 'Service', {
  cluster,
  memoryLimitMiB: 1024,
  cpu: 512,
  taskImageOptions: {
    image: ecs.ContainerImage.fromRegistry("amazon/amazon-ecs-sample"),
    command: ['command'],
    entryPoint: ['entry', 'point'],
  },
  containerCpu: 256,
  containerMemoryLimitMiB: 512,
  minHealthyPercent: 100,
});

loadBalancedFargateService.targetGroup.configureHealthCheck({
  path: "/custom-health-path",
});
python
# cluster: ecs.Cluster

load_balanced_fargate_service = ecs_patterns.ApplicationLoadBalancedFargateService(self, "Service",
    cluster=cluster,
    memory_limit_mi_b=1024,
    cpu=512,
    task_image_options=ecsPatterns.ApplicationLoadBalancedTaskImageOptions(
        image=ecs.ContainerImage.from_registry("amazon/amazon-ecs-sample"),
        command=["command"],
        entry_point=["entry", "point"]
    ),
    container_cpu=256,
    container_memory_limit_mi_b=512,
    min_healthy_percent=100
)

load_balanced_fargate_service.target_group.configure_health_check(
    path="/custom-health-path"
)
java
Cluster cluster;

ApplicationLoadBalancedFargateService loadBalancedFargateService = ApplicationLoadBalancedFargateService.Builder.create(this, "Service")
        .cluster(cluster)
        .memoryLimitMiB(1024)
        .cpu(512)
        .taskImageOptions(ApplicationLoadBalancedTaskImageOptions.builder()
                .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                .command(List.of("command"))
                .entryPoint(List.of("entry", "point"))
                .build())
        .containerCpu(256)
        .containerMemoryLimitMiB(512)
        .minHealthyPercent(100)
        .build();

loadBalancedFargateService.targetGroup.configureHealthCheck(HealthCheck.builder()
        .path("/custom-health-path")
        .build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Cluster cluster;

var loadBalancedFargateService = new ApplicationLoadBalancedFargateService(this, "Service", new ApplicationLoadBalancedFargateServiceProps {
    Cluster = cluster,
    MemoryLimitMiB = 1024,
    Cpu = 512,
    TaskImageOptions = new ApplicationLoadBalancedTaskImageOptions {
        Image = ContainerImage.FromRegistry("amazon/amazon-ecs-sample"),
        Command = new [] { "command" },
        EntryPoint = new [] { "entry", "point" }
    },
    ContainerCpu = 256,
    ContainerMemoryLimitMiB = 512,
    MinHealthyPercent = 100
});

loadBalancedFargateService.TargetGroup.ConfigureHealthCheck(new HealthCheck {
    Path = "/custom-health-path"
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var cluster Cluster

loadBalancedFargateService := ecsPatterns.NewApplicationLoadBalancedFargateService(this, jsii.String("Service"), &ApplicationLoadBalancedFargateServiceProps{
	Cluster: Cluster,
	MemoryLimitMiB: jsii.Number(1024),
	Cpu: jsii.Number(512),
	TaskImageOptions: &ApplicationLoadBalancedTaskImageOptions{
		Image: ecs.ContainerImage_FromRegistry(jsii.String("amazon/amazon-ecs-sample")),
		Command: []*string{
			jsii.String("command"),
		},
		EntryPoint: []*string{
			jsii.String("entry"),
			jsii.String("point"),
		},
	},
	ContainerCpu: jsii.Number(256),
	ContainerMemoryLimitMiB: jsii.Number(512),
	MinHealthyPercent: jsii.Number(100),
})

loadBalancedFargateService.TargetGroup.ConfigureHealthCheck(&HealthCheck{
	Path: jsii.String("/custom-health-path"),
})

Properties ​

enabledoptionalbooleanenabledoptionalboolenabledoptionalBooleanEnabledoptionalboolEnabledoptional*bool #
Indicates whether health checks are enabled.

Default: Determined automatically.

If the target type is lambda, health checks are disabled by default but can be enabled. If the target type is instance or ip, health checks are always enabled and cannot be disabled.

healthyGrpcCodesoptionalstringhealthy_grpc_codesoptionalstrhealthyGrpcCodesoptionalStringHealthyGrpcCodesoptionalstringHealthyGrpcCodesoptional*string = 12 #
GRPC code to use when checking for a successful response from a target.

You can specify values between 0 and 99. You can specify multiple values (for example, "0,1") or a range of values (for example, "0-5").

healthyHttpCodesoptionalstringhealthy_http_codesoptionalstrhealthyHttpCodesoptionalStringHealthyHttpCodesoptionalstringHealthyHttpCodesoptional*string #
HTTP code to use when checking for a successful response from a target.

For Application Load Balancers, you can specify values between 200 and 499, and the default value is 200. You can specify multiple values (for example, "200,202") or a range of values (for example, "200-299").

healthyThresholdCountoptionalnumberhealthy_threshold_countoptionalint | floathealthyThresholdCountoptionalNumberHealthyThresholdCountoptionaldoubleHealthyThresholdCountoptional*float64 #
The number of consecutive health checks successes required before considering an unhealthy target healthy.

Default: 5 for ALBs, 3 for NLBs

For Application Load Balancers, the default is 5. For Network Load Balancers, the default is 3.

intervaloptionalDurationintervaloptionalDurationintervaloptionalDurationIntervaloptionalDurationIntervaloptionalDuration #
The approximate number of seconds between health checks for an individual target.

Default: 10 seconds if protocol is GENEVE, 35 seconds if target type is lambda, else 30 seconds

Must be 5 to 300 seconds

pathoptionalstringpathoptionalstrpathoptionalStringPathoptionalstringPathoptional*string = / #
The ping path destination where Elastic Load Balancing sends health check requests.
portoptionalstringportoptionalstrportoptionalStringPortoptionalstringPortoptional*string = 'traffic-port' #
The port that the load balancer uses when performing health checks on the targets.
protocoloptionalProtocolprotocoloptionalProtocolprotocoloptionalProtocolProtocoloptionalProtocolProtocoloptionalProtocol #
The protocol the load balancer uses when performing health checks on targets.

Default: HTTP for ALBs, TCP for NLBs

The TCP protocol is supported for health checks only if the protocol of the target group is TCP, TLS, UDP, or TCP_UDP. The TLS, UDP, and TCP_UDP protocols are not supported for health checks.

timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration #
The amount of time, in seconds, during which no response from a target means a failed health check.

Default: 6 seconds if the protocol is HTTP, 5 seconds if protocol is GENEVE, 30 seconds if target type is lambda, 10 seconds for TCP, TLS, or HTTPS

Must be 2 to 120 seconds.

unhealthyThresholdCountoptionalnumberunhealthy_threshold_countoptionalint | floatunhealthyThresholdCountoptionalNumberUnhealthyThresholdCountoptionaldoubleUnhealthyThresholdCountoptional*float64 = 2 #
The number of consecutive health check failures required before considering a target unhealthy.

For Application Load Balancers, the default is 2. For Network Load Balancers, the range is between 2-10 and can be set accordingly.