Registry /
aws / aws-cdk-aws-elasticloadbalancing
Install & Compatibility
Where this runs
tested against v1.204.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 48.6MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.6s · import 0.000s · 49MB
50MB installed
● package 50MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CfnLoadBalancer
✓ from aws_cdk import aws_elasticloadbalancing as elb
✗ from aws_cdk.aws_elasticloadbalancingv2 import ApplicationLoadBalancer
This library is for Classic Load Balancers (ELBv1). For Application or Network Load Balancers, use `aws_cdk.aws_elasticloadbalancingv2`.
This quickstart deploys a basic AWS Classic Load Balancer (ELBv1) within a new VPC using CDK v1. It creates an internet-facing load balancer with an HTTP listener on port 80, routing traffic to instances (not shown) on port 80. Ensure `CDK_DEFAULT_ACCOUNT` and `CDK_DEFAULT_REGION` environment variables are set.
import os
from aws_cdk import (
App, Stack, Environment,
aws_ec2 as ec2,
aws_elasticloadbalancing as elb,
CfnOutput
)
from constructs import Construct
class ElbV1Stack(Stack):
def __init__(self, scope: Construct, id: str, **kwargs) -> None:
super().__init__(scope, id, **kwargs)
# Create a VPC
vpc = ec2.Vpc(self, "MyVpc",
max_azs=2,
cidr="10.10.0.0/16",
subnet_configuration=[
ec2.SubnetConfiguration(
name="Public",
subnet_type=ec2.SubnetType.PUBLIC,
cidr_mask=24
),
ec2.SubnetConfiguration(
name="Private",
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED,
cidr_mask=24
)
]
)
# Select public subnets for the Classic Load Balancer
public_subnets = vpc.select_subnets(subnet_type=ec2.SubnetType.PUBLIC)
# Create a Classic Load Balancer
clb = elb.CfnLoadBalancer(self, "MyClassicLoadBalancer",
listeners=[
elb.CfnLoadBalancer.ListenersProperty(
instance_port="80",
instance_protocol="HTTP",
load_balancer_port="80",
protocol="HTTP"
)
],
scheme="internet-facing",
subnets=[s.subnet_id for s in public_subnets.subnets]
# For production, consider adding security_groups and health_check.
# The CLB will create a default security group if none is provided.
)
CfnOutput(self, "LoadBalancerDNS", value=clb.get_att("DNSName").to_string())
app = App()
ElbV1Stack(app, "ElbV1ExampleStack",
env=Environment(
account=os.environ.get("CDK_DEFAULT_ACCOUNT"),
region=os.environ.get("CDK_DEFAULT_REGION")
)
)
app.synth()
cdk --version
Debug
Known issues
breakingAWS CDK v1 to v2 migration involves significant breaking changes across the entire CDK ecosystem. This `aws-cdk.aws-elasticloadbalancing` library is specific to CDK v1 and is not compatible with CDK v2 without a full migration of your CDK application.fixMigrate your CDK application to v2 and use the equivalent `aws-cdk.aws-elasticloadbalancingv2` or `aws-cdk.aws-ec2` constructs where applicable, following the official AWS CDK migration guide.
affects: All v1.x versions when migrating to v2.x
gotchaThis library specifically manages *Classic Load Balancers (ELBv1)*. Do not confuse it with Application Load Balancers (ALB) or Network Load Balancers (NLB), which are managed by the `aws-cdk.aws-elasticloadbalancingv2` library.fixFor ALB or NLB, ensure you install and import from `aws-cdk.aws-elasticloadbalancingv2`. For Classic Load Balancers, continue using this library.
affects: All v1.x versions
deprecatedAWS Classic Load Balancers themselves are considered a legacy service by AWS, with Application and Network Load Balancers being the recommended modern alternatives. New deployments should generally prefer ELBv2 constructs.fixConsider using `aws-cdk.aws-elasticloadbalancingv2` for new load balancer deployments, leveraging Application or Network Load Balancers for improved features and performance.
affects: All v1.x versions
Upgrade
Version history
1.204.0latest on PyPI · released Jun 19, 2023
Audit
Dependencies
aws-cdk.corerequiredRequired for all CDK applications, providing core constructs like App and Stack.
aws-cdk.aws-ec2requiredNeeded for provisioning network resources like VPCs and subnets, essential for Classic Load Balancer deployment.
constructsrequiredThe low-level building blocks for CDK applications, foundational for all CDK constructs.