HttpCodeTarget

class aws_cdk.aws_elasticloadbalancingv2.HttpCodeTarget(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

Count of HTTP status originating from the targets.

ExampleMetadata:

infused

Example:

import aws_cdk.aws_cloudwatch as cloudwatch

# service: ecs.FargateService
# blue_target_group: elbv2.ApplicationTargetGroup
# green_target_group: elbv2.ApplicationTargetGroup
# listener: elbv2.IApplicationListener


# Alarm on the number of unhealthy ECS tasks in each target group
blue_unhealthy_hosts = cloudwatch.Alarm(self, "BlueUnhealthyHosts",
    alarm_name=Stack.of(self).stack_name + "-Unhealthy-Hosts-Blue",
    metric=blue_target_group.metric_unhealthy_host_count(),
    threshold=1,
    evaluation_periods=2
)

green_unhealthy_hosts = cloudwatch.Alarm(self, "GreenUnhealthyHosts",
    alarm_name=Stack.of(self).stack_name + "-Unhealthy-Hosts-Green",
    metric=green_target_group.metric_unhealthy_host_count(),
    threshold=1,
    evaluation_periods=2
)

# Alarm on the number of HTTP 5xx responses returned by each target group
blue_api_failure = cloudwatch.Alarm(self, "Blue5xx",
    alarm_name=Stack.of(self).stack_name + "-Http-5xx-Blue",
    metric=blue_target_group.metric_http_code_target(elbv2.HttpCodeTarget.TARGET_5XX_COUNT, period=Duration.minutes(1)),
    threshold=1,
    evaluation_periods=1
)

green_api_failure = cloudwatch.Alarm(self, "Green5xx",
    alarm_name=Stack.of(self).stack_name + "-Http-5xx-Green",
    metric=green_target_group.metric_http_code_target(elbv2.HttpCodeTarget.TARGET_5XX_COUNT, period=Duration.minutes(1)),
    threshold=1,
    evaluation_periods=1
)

codedeploy.EcsDeploymentGroup(self, "BlueGreenDG",
    # CodeDeploy will monitor these alarms during a deployment and automatically roll back
    alarms=[blue_unhealthy_hosts, green_unhealthy_hosts, blue_api_failure, green_api_failure],
    auto_rollback=codedeploy.AutoRollbackConfig(
        # CodeDeploy will automatically roll back if a deployment is stopped
        stopped_deployment=True
    ),
    service=service,
    blue_green_deployment_config=codedeploy.EcsBlueGreenDeploymentConfig(
        blue_target_group=blue_target_group,
        green_target_group=green_target_group,
        listener=listener
    ),
    deployment_config=codedeploy.EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES
)

Attributes

TARGET_2XX_COUNT

The number of 2xx response codes from targets.

TARGET_3XX_COUNT

The number of 3xx response codes from targets.

TARGET_4XX_COUNT

The number of 4xx response codes from targets.

TARGET_5XX_COUNT

The number of 5xx response codes from targets.