Skip to main content

Reusable CDK construct to add ALB Target Group

Project description

AWS CDK Target Group

An AWS CDK construct for creating Application Load Balancer (ALB) Target Groups with health checks and conditional deregistration delays.

Overview

This CDK construct creates an Elastic Load Balancing V2 Target Group with the following features:

  • VPC Integration: Imports VPC from an existing ECS stack
  • Health Checks: Configurable HTTP health checks with custom paths
  • Conditional Logic: Different deregistration delays for dev vs production environments
  • Flexible Configuration: Parameterized port, protocol, and health check settings

Features

  • ✅ HTTP/HTTPS protocol support
  • ✅ Customizable health check endpoints
  • ✅ Environment-specific deregistration delays (0s for dev, configurable for prod)
  • ✅ Health check status codes 200-299
  • ✅ Configurable health check intervals and timeouts
  • ✅ CloudFormation outputs for target group ARN

Usage

from aws_cdk import Stack
from constructs import Construct
from alb_target_group import TargetGroupStack

class MyStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs):
        super().__init__(scope, construct_id, **kwargs)
        
        target_group = TargetGroupStack(
            self, "MyTargetGroup",
            ecs_stack_name="my-ecs-stack",
            health_check_path="/api/health",
            channel="prod",  # or "dev"
            port=80,
            protocol="HTTP",
            max_request_duration=300,
            health_threshold_count=2,
            health_check_timeout_seconds=5,
            health_check_interval_seconds=10
        )

Configuration Parameters

Parameter Type Description
ecs_stack_name string Name of the ECS stack to import VPC from
health_check_path string Path for health check endpoint (e.g., /api/health)
channel string Environment channel (dev or prod)
port int Target group port (e.g., 80, 443)
protocol string Protocol (HTTP or HTTPS)
max_request_duration int Max request duration in seconds (used for non-dev deregistration delay)
health_threshold_count int Number of consecutive successful health checks required
health_check_timeout_seconds int Health check timeout in seconds
health_check_interval_seconds int Health check interval in seconds

Environment Behavior

  • Dev Environment (channel="dev"): Deregistration delay is set to 0 seconds for faster deployments
  • Production Environment (any other channel): Deregistration delay uses the max_request_duration value

Outputs

The construct exports:

  • TargetGroupArn: The ARN of the created target group

Requirements

  • AWS CDK v2
  • Python 3.7+

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alb-target-group-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

alb_target_group-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file alb-target-group-0.1.0.tar.gz.

File metadata

  • Download URL: alb-target-group-0.1.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for alb-target-group-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6c3aa6c748261800b794123af52d07213b1640586a21fdd1372c71b617ff9a2b
MD5 50c90b9f4ff93b8ab9db0b63c1e954f2
BLAKE2b-256 b3cbc01cceba12a082620ff2eb6a42c46db54e4273063dceab71b0be8351934e

See more details on using hashes here.

File details

Details for the file alb_target_group-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for alb_target_group-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b9e363966b8d40ec91e335976e47fe10e98eacb8b3506f5f4ad36ef9f157316
MD5 d65d4d2d935b65876c590cb4d8d0748b
BLAKE2b-256 8b7272e89e455903819801fe247e972a7844aa883cc1d631b7da0e3eececb0fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page