Reusable CDK construct to add ALB listener rules
Project description
AWS CDK Public Listener Role
A CDK construct for creating Application Load Balancer (ALB) listener rules that route traffic based on host headers to target groups.
Overview
This module provides a reusable CDK construct (AlbListenerRuleStack) that creates ALB listener rules for routing HTTP/HTTPS traffic to specific target groups based on host header conditions.
Features
- Creates ALB listener rules with host-based routing
- Configurable priority for rule evaluation order
- Integrates with existing ALB listeners via CloudFormation exports
- Outputs rule ARN and priority for cross-stack references
Usage
from alb_listener_rule.alb_listener_rule_stack import AlbListenerRuleStack
# Create listener rule in your CDK stack
listener_rule = AlbListenerRuleStack(
self, "MyListenerRule",
target_group_arn="arn:aws:elasticloadbalancing:region:account:targetgroup/my-tg/1234567890",
ecs_stack_name="my-ecs-stack",
listener_priority=100,
host_name="api.example.com"
)
Parameters
| Parameter | Type | Description |
|---|---|---|
target_group_arn |
str | ARN of the target group to forward traffic to |
ecs_stack_name |
str | Name of the ECS stack that exports the ALB listener ARN |
listener_priority |
int | Priority for the listener rule (1-50000, lower = higher priority) |
host_name |
str | Host header value to match for routing |
Prerequisites
- An existing ALB with HTTPS listener that exports its ARN as
${ECSStackName}-ALBListenerHTTPS - A target group (e.g., ECS service target group) to route traffic to
Outputs
The construct exports the following CloudFormation outputs:
${StackName}-AlbListenerRuleArn: ARN of the created listener rule${StackName}-AlbListenerRulePriority: Priority of the created listener rule
Example Scenario
This construct is useful when you have:
- An ECS cluster with an ALB
- Multiple services that need different routing rules
- Requirements to route traffic based on domain/subdomain
File Structure
aws_cdk-public-listener-role/
├── README.md
└── alb_listener_rule/
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-listener-rule-0.1.0.tar.gz.
File metadata
- Download URL: alb-listener-rule-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d5e730f606231bd723b4e2095f0b620bd6e100187d1f1c9a890011ae3ff3a22
|
|
| MD5 |
ac1904ee9160177d3f377ed6a32ea9bf
|
|
| BLAKE2b-256 |
eed2bd182093b16a01e3b57b14433f1b2f44d53676613725a3935e0c604dffdf
|
File details
Details for the file alb_listener_rule-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alb_listener_rule-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 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 |
649f0b59f05020cecef5688d849c5c00b19c23a0102ff5d6dd083ea4366a38c5
|
|
| MD5 |
bedac4f2978de1fb519c6a972bd4360d
|
|
| BLAKE2b-256 |
c387b6d24c7fdeadad2c3261753b45c183298f59690ee2ba468ecb36ba1cae09
|