Skip to content
betterstack-alchemyUnofficial

Cloud.LoadBalancer

Kind ResourceType id BetterStack.Cloud.LoadBalancerSource src/Cloud/LoadBalancer.tsLive test gated Lifecycle test runs against the offline mock; a live run exists but is gated behind BETTERSTACK_TEST_CLOUD_BILLABLE=1 because it bills; live runs need the owner's go-ahead (test/Cloud/LoadBalancer.test.ts).

A Better Stack Cloud load balancer: spreads TCP, UDP, HTTP and HTTPS traffic over your servers. It has services that listen for traffic (LoadBalancerService: protocol, ports, health check, TLS, sticky sessions) and targets that receive it (LoadBalancerTarget: a server, or every server with a tag). Both are their own resources that take the load balancer’s id, so adding a service or a target never touches the load balancer itself.

A load balancer bills by its type for the billing term: monthly by default; annual commits you to paying for a year. Creating one waits until it is running (up to 20 minutes; failed stops the deploy).

What changes in place: name, algorithm, metadata, term (update); type (a rescale, waited for until running with the new type); networkIds and firewallIds (attach/detach actions). teamId and availabilityZone replace it. Deleting it removes its services and targets; it may still answer with status: "destroyed" for a while, which counts as gone.

Coming from Hetzner: services[] and targets[] of a Hetzner load balancer are separate resources here, services[].healthCheck is LoadBalancerService.healthCheck, a server target is LoadBalancerTarget({ type: "server", serverId }), a label selector target is type: "label_selector", and networks is networkIds.

Ownership. Every object the stack creates carries an alchemy entry in its metadata (<stack>/<stage>/<resource id>#<instance>), added on every write and left out of the attributes and of diffs; your own keys are untouched (it takes one of the 10 slots). A deploy that lost track of an object it created (a create that failed or was interrupted after the API accepted it) finds it by that marker and converges it instead of creating another; list (and so alchemy nuke) returns only Alchemy-created objects; an object that matches but carries no marker of this resource is taken over only with --adopt.

A load balancer with an HTTP service and a server target

const lb = yield* BetterStack.Cloud.LoadBalancer("edge", {
type: "LB1",
algorithm: "least_connections",
});
yield* BetterStack.Cloud.LoadBalancerService("http", {
loadBalancerId: lb.id,
protocol: "http",
listenPort: 80,
destinationPort: 8080,
healthCheck: { protocol: "http", path: "/health" },
});
yield* BetterStack.Cloud.LoadBalancerTarget("web", {
loadBalancerId: lb.id,
type: "server",
serverId: server.id,
});

Reach targets over a private network, behind a firewall

const network = yield* BetterStack.Cloud.Network("private", {
ipPrefix: "10.0.0.0",
ipPrefixLength: 24,
});
const lb = yield* BetterStack.Cloud.LoadBalancer("internal", {
type: "LB1",
networkIds: [network.id],
firewallIds: [firewallId],
});
yield* BetterStack.Cloud.LoadBalancerTarget("workers", {
loadBalancerId: lb.id,
type: "label_selector",
selector: { role: "worker" },
usePrivateIp: true,
});

Change the type in place

const lb = yield* BetterStack.Cloud.LoadBalancer("edge", { type: "LB2" });

Reference a load balancer by id

const existing = BetterStack.Cloud.LoadBalancer.lookup({ id: "42" });

Reference a load balancer by name (fails with AmbiguousLookup when several share it)

const byName = BetterStack.Cloud.LoadBalancer.lookup({ name: "web-lb" });

type string required

The load balancer's type, such as LB1 (listLoadBalancerType lists them). Changing it rescales the load balancer in place, and the deploy waits until it is running with the new type.

algorithm "round_robin" | "least_connections" | "source_ip" | string

How the load balancer picks a target for each connection. - round_robin: Sends each new connection to the next target in turn. - least_connections: Sends each new connection to the target with the fewest open connections. - source_ip: Sends all connections from one client IP to the same target.

availabilityZone string

Availability zone the resource lives in, such as us-west-2a. Defaults to the credentials' zone (BETTERSTACK_AVAILABILITY_ZONE, or the profile's). Changing it replaces the resource. A child of a resource in another zone (a firewall rule, a node pool, a snapshot of an instance outside the credentials' zone) must repeat the parent's availabilityZone: it receives only the parent's id, so its zone cannot be derived.

firewallIds string[]

The ID of the firewall to attach, at most one (firewall.id). A change detaches the old firewall before attaching the new one, in place. Leaving the prop out keeps whatever is attached; [] detaches it.

metadata CreateLoadBalancerRequestMetadataMap

Your own tags as string pairs. An update replaces all tags, so an empty object removes every tag.

name string

The load balancer's name. Defaults to a unique name generated from the stack, stage and logical id.

networkIds string[]

The IDs of the private networks to attach (network.id). Changes attach and detach in place. Leaving the prop out keeps whatever is attached; [] detaches every network.

teamId string

Team that owns the resource, such as t123. Defaults to the credentials' team (BETTERSTACK_TEAM_ID, or the profile's team). Changing it replaces the resource.

term "monthly" | "annual"

The billing term, monthly (the default) or annual. annual commits you to paying for a year. A change applies at once, in place: billing ends the current term and starts the new one.

availabilityZone string always set

Availability zone the resource lives in, such as us-west-2a.

id string always set

The load balancer's ID. Pass it to [LoadBalancerService](/reference/cloud/loadbalancerservice/) and [LoadBalancerTarget](/reference/cloud/loadbalancertarget/).

algorithm "round_robin" | "least_connections" | "source_ip"

How the load balancer picks a target for each connection. - round_robin: Sends each new connection to the next target in turn. - least_connections: Sends each new connection to the target with the fewest open connections. - source_ip: Sends all connections from one client IP to the same target.

configAppliedAt string | null

When we last applied the configuration to the load balancer, or null until we first apply it.

createdAt string

When the load balancer was created.

firewallIds string[]

The IDs of the firewalls attached to the load balancer, at most one.

metadata LoadBalancerMetadataMap

Your own tags as string pairs. An update replaces all tags, so an empty object removes every tag.

name string

The load balancer's name.

networkIds string[]

The IDs of the networks attached to the load balancer.

privateIps KafkaBrokersItemPrivateIpsItem[]

The load balancer's private IP in each attached network.

publicIps LoadBalancerPublicIpsItem[]

The load balancer's public IP addresses, one IPv4 and one IPv6.

services LoadBalancerServicesItem[]

The services that listen for traffic, with their settings and the latest health of each target. Add, update or remove them with betterstack load-balancer-service.

status string

The load balancer's state. - provisioning: We're starting the load balancer. - running: The load balancer is ready. status_message reports any problem. config_applied_at says when we last applied your configuration. - rescaling: We're changing the load balancer's type. The load balancer returns to running even when the change didn't finish. The load balancer's events say how the change went. - failed: We couldn't create the load balancer. status_message says why. - destroyed: The load balancer is deleted.

statusMessage string | null

What went wrong while we created or configured the load balancer, or what's wrong with it now. Is null when there's nothing to report.

targets LoadBalancerTargetSummary[]

The targets added with [LoadBalancerTarget](/reference/cloud/loadbalancertarget/). A label_selector target shows as one entry. Its selector is parsed into an object.

teamId string

The ID of the team that owns the load balancer. Can't be changed after the load balancer is created.

term "monthly" | "annual"

The billing term. A change applies at once, from monthly to annual or back. Billing ends the current term and starts the new one. Sending the current term changes nothing. - monthly: Billed every month. - annual: Paid for a year.

type string

The load balancer's type, such as LB1.

updatedAt string

When the load balancer was last updated.

LoadBalancer.lookup(props) reads an object this stack does not manage. It is never created, updated or deleted.

availabilityZone string

Zone it lives in, such as us-west-2a. Defaults to the credentials' zone.