Skip to content
v2.278.0

HealthCheck Struct ​

The health check command and associated configuration parameters for the container.

Example ​

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'),
  minHealthyPercent: 100,
  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),
  },
});
python
# vpc: ec2.Vpc
# security_group: ec2.SecurityGroup

queue_processing_fargate_service = ecs_patterns.QueueProcessingFargateService(self, "Service",
    vpc=vpc,
    memory_limit_mi_b=512,
    image=ecs.ContainerImage.from_registry("test"),
    min_healthy_percent=100,
    health_check=ecs.HealthCheck(
        command=["CMD-SHELL", "curl -f http://localhost/ || exit 1"],
        # the properties below are optional
        interval=Duration.minutes(30),
        retries=123,
        start_period=Duration.minutes(30),
        timeout=Duration.minutes(30)
    )
)
java
Vpc vpc;
SecurityGroup securityGroup;

QueueProcessingFargateService queueProcessingFargateService = QueueProcessingFargateService.Builder.create(this, "Service")
        .vpc(vpc)
        .memoryLimitMiB(512)
        .image(ContainerImage.fromRegistry("test"))
        .minHealthyPercent(100)
        .healthCheck(HealthCheck.builder()
                .command(List.of("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))
                .build())
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
SecurityGroup securityGroup;

var queueProcessingFargateService = new QueueProcessingFargateService(this, "Service", new QueueProcessingFargateServiceProps {
    Vpc = vpc,
    MemoryLimitMiB = 512,
    Image = ContainerImage.FromRegistry("test"),
    MinHealthyPercent = 100,
    HealthCheck = new HealthCheck {
        Command = new [] { "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)
    }
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var securityGroup SecurityGroup

queueProcessingFargateService := ecsPatterns.NewQueueProcessingFargateService(this, jsii.String("Service"), &QueueProcessingFargateServiceProps{
	Vpc: Vpc,
	MemoryLimitMiB: jsii.Number(512),
	Image: ecs.ContainerImage_FromRegistry(jsii.String("test")),
	MinHealthyPercent: jsii.Number(100),
	HealthCheck: &HealthCheck{
		Command: []*string{
			jsii.String("CMD-SHELL"),
			jsii.String("curl -f http://localhost/ || exit 1"),
		},
		// the properties below are optional
		Interval: awscdk.Duration_Minutes(jsii.Number(30)),
		Retries: jsii.Number(123),
		StartPeriod: awscdk.Duration_*Minutes(jsii.Number(30)),
		Timeout: awscdk.Duration_*Minutes(jsii.Number(30)),
	},
})

Properties ​

commandstring[]commandtyping.List[str]commandList<String>Commandstring[]Command*[]*string required #
A string array representing the command that the container runs to determine if it is healthy.

The string array must start with CMD to execute the command arguments directly, or CMD-SHELL to run the command with the container's default shell.

For example: [ "CMD-SHELL", "curl -f http://localhost/ || exit 1" ]

intervaloptionalDurationintervaloptionalDurationintervaloptionalDurationIntervaloptionalDurationIntervaloptionalDuration = Duration.seconds(30) #
The time period in seconds between each health check execution.

You may specify between 5 and 300 seconds.

retriesoptionalnumberretriesoptionalint | floatretriesoptionalNumberRetriesoptionaldoubleRetriesoptional*float64 = 3 #
The number of times to retry a failed health check before the container is considered unhealthy.

You may specify between 1 and 10 retries.

startPeriodoptionalDurationstart_periodoptionalDurationstartPeriodoptionalDurationStartPeriodoptionalDurationStartPeriodoptionalDuration #
The optional grace period within which to provide containers time to bootstrap before failed health checks count towards the maximum number of retries.

Default: No start period

You may specify between 0 and 300 seconds.

timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration = Duration.seconds(5) #
The time period in seconds to wait for a health check to succeed before it is considered a failure.

You may specify between 2 and 60 seconds.