Load Balancer
Emulated load balancers, target groups, listeners, and health checks, modelled on ELB and cloud LBs
aws ELBazr LBgcp LB
Emulates a managed load balancer — the ELB-style front door that spreads traffic across a pool of backends. You create a load balancer, register targets in a target group, and attach a listener that routes a port to that group.
Reach for it in tests when your code provisions load balancers, registers or deregisters targets, or reacts to target health — so you can exercise those paths without a live LB. Under the hood a load balancer, its target groups, and its listeners are plain named records wired together by ID.
| Provider | Service | Driver |
|---|---|---|
| AWS | ELB | aws.ELB |
| Azure | LB | azure.LB |
| GCP | LB | gcp.LB |
Create a load balancer#
The load balancer is the entry point clients connect to — the equivalent of provisioning an Application Load Balancer. Create one before wiring up targets or listeners:
import lbdriver "github.com/stackshy/cloudemu/v2/services/loadbalancer/driver"
lb, _ := aws.ELB.CreateLoadBalancer(ctx, lbdriver.LoadBalancerConfig{
Name: "web-lb",
Type: "application",
Scheme: "internet-facing",
})Create a target group and register targets#
A target group is the pool of backends the load balancer sends traffic to, along with the health check that decides which are eligible. Register your instances into it:
tg, _ := aws.ELB.CreateTargetGroup(ctx, lbdriver.TargetGroupConfig{
Name: "web-targets",
Port: 8080,
Protocol: "HTTP",
})
aws.ELB.RegisterTargets(ctx, tg.ID, []string{"i-00000001", "i-00000002"})Attach a listener#
A listener binds a port and protocol on the load balancer to a target group — this is what actually forwards incoming requests to your backends:
aws.ELB.CreateListener(ctx, lbdriver.ListenerConfig{
LoadBalancerID: lb.ID,
Port: 443,
Protocol: "HTTPS",
TargetGroupID: tg.ID,
})Behavior & fidelity#
- Target groups carry health-check configuration. Each group's health check determines the health status of its registered targets, so you can test how your code responds to a target going unhealthy.
- Objects are wired by ID. Listeners reference a load balancer and a target group by ID, mirroring how ELB resources compose; a target group can back more than one listener.
- SDK-compat status — Portable Go API only. Real
elbv2,armnetwork.LoadBalancers, and GCP LB clients can't talk to cloudemu yet — load balancer SDK-compat handlers will ship in lockstep across all three providers in a future phase. Targets, listeners, and health checks are available today through the Portable Go API shown above.