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_durationvalue
Outputs
The construct exports:
TargetGroupArn: The ARN of the created target group
Requirements
- AWS CDK v2
- Python 3.7+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c3aa6c748261800b794123af52d07213b1640586a21fdd1372c71b617ff9a2b
|
|
| MD5 |
50c90b9f4ff93b8ab9db0b63c1e954f2
|
|
| BLAKE2b-256 |
b3cbc01cceba12a082620ff2eb6a42c46db54e4273063dceab71b0be8351934e
|
File details
Details for the file alb_target_group-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alb_target_group-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b9e363966b8d40ec91e335976e47fe10e98eacb8b3506f5f4ad36ef9f157316
|
|
| MD5 |
d65d4d2d935b65876c590cb4d8d0748b
|
|
| BLAKE2b-256 |
8b7272e89e455903819801fe247e972a7844aa883cc1d631b7da0e3eececb0fb
|