aws-cdk-lib.aws_elasticloadbalancingv2.HttpCodeTarget

enum HttpCodeTarget

LanguageType name
.NETAmazon.CDK.AWS.ElasticLoadBalancingV2.HttpCodeTarget
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awselasticloadbalancingv2#HttpCodeTarget
Javasoftware.amazon.awscdk.services.elasticloadbalancingv2.HttpCodeTarget
Pythonaws_cdk.aws_elasticloadbalancingv2.HttpCodeTarget
TypeScript (source)aws-cdk-lib » aws_elasticloadbalancingv2 » HttpCodeTarget

Count of HTTP status originating from the targets.

Example

import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';

declare const service: ecs.FargateService;
declare const blueTargetGroup: elbv2.ApplicationTargetGroup;
declare const greenTargetGroup: elbv2.ApplicationTargetGroup;
declare const listener: elbv2.IApplicationListener;

// Alarm on the number of unhealthy ECS tasks in each target group
const blueUnhealthyHosts = new cloudwatch.Alarm(this, 'BlueUnhealthyHosts', {
  alarmName: Stack.of(this).stackName + '-Unhealthy-Hosts-Blue',
  metric: blueTargetGroup.metricUnhealthyHostCount(),
  threshold: 1,
  evaluationPeriods: 2,
});

const greenUnhealthyHosts = new cloudwatch.Alarm(this, 'GreenUnhealthyHosts', {
  alarmName: Stack.of(this).stackName + '-Unhealthy-Hosts-Green',
  metric: greenTargetGroup.metricUnhealthyHostCount(),
  threshold: 1,
  evaluationPeriods: 2,
});

// Alarm on the number of HTTP 5xx responses returned by each target group
const blueApiFailure = new cloudwatch.Alarm(this, 'Blue5xx', {
  alarmName: Stack.of(this).stackName + '-Http-5xx-Blue',
  metric: blueTargetGroup.metricHttpCodeTarget(
    elbv2.HttpCodeTarget.TARGET_5XX_COUNT,
    { period: Duration.minutes(1) },
  ),
  threshold: 1,
  evaluationPeriods: 1,
});

const greenApiFailure = new cloudwatch.Alarm(this, 'Green5xx', {
  alarmName: Stack.of(this).stackName + '-Http-5xx-Green',
  metric: greenTargetGroup.metricHttpCodeTarget(
    elbv2.HttpCodeTarget.TARGET_5XX_COUNT,
    { period: Duration.minutes(1) },
  ),
  threshold: 1,
  evaluationPeriods: 1,
});

new codedeploy.EcsDeploymentGroup(this, 'BlueGreenDG', {
  // CodeDeploy will monitor these alarms during a deployment and automatically roll back
  alarms: [blueUnhealthyHosts, greenUnhealthyHosts, blueApiFailure, greenApiFailure],
  autoRollback: {
    // CodeDeploy will automatically roll back if a deployment is stopped
    stoppedDeployment: true,
  },
  service,
  blueGreenDeploymentConfig: {
    blueTargetGroup,
    greenTargetGroup,
    listener,
  },
  deploymentConfig: codedeploy.EcsDeploymentConfig.CANARY_10PERCENT_5MINUTES,
});

Members

NameDescription
TARGET_2XX_COUNTThe number of 2xx response codes from targets.
TARGET_3XX_COUNTThe number of 3xx response codes from targets.
TARGET_4XX_COUNTThe number of 4xx response codes from targets.
TARGET_5XX_COUNTThe number of 5xx response codes from targets.

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.