Skip to content
betterstack-alchemyUnofficial

Cloud.LoadBalancerService

Kind ResourceType id BetterStack.Cloud.LoadBalancerServiceSource src/Cloud/LoadBalancerService.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/LoadBalancerService.test.ts).

A service of a Better Stack Cloud LoadBalancer: it listens on one port (listenPort) for tcp, udp, http or https traffic and forwards it to destinationPort on the load balancer’s healthy targets. Each service checks its targets’ health on its own, and reports it in targetHealth.

Every setting changes in place; only loadBalancerId (and the zone) replaces the service. Services are free; they go away with their load balancer.

  • https terminates TLS with the Cloud.Certificates in certificateIds (at least one), and redirectHttp: true redirects plain HTTP to it.
  • healthCheck is merged on update: a field you remove from the config keeps its last value on the API (set it explicitly to change it). Without one, tcp/udp services check a TCP connect and http/https services an HTTP request, on destinationPort.
  • stickySessions (http/https) pins a client to a target with a cookie.
  • proxyProtocol: "v1" | "v2" tells the targets the client’s address.
  • Ports 8402 and 9901 are the load balancer’s own.

Ownership. The API keeps no metadata for it and it has no generated name, so nothing marks it as this stack’s: list enumerates it under every parent, and a create interrupted before its state was saved is not recognised by the next deploy (which creates it again, or gets the API’s conflict when its identity is unique).

Zone. A child doesn’t take its zone from its parent: it uses its own availabilityZone, else the credentials’ zone. When the parent lives in another zone, pass the parent’s along (availabilityZone: parent.availabilityZone), or every call for it answers NotFound.

Forward TCP port 80 to 8080

const lb = yield* BetterStack.Cloud.LoadBalancer("edge", { type: "LB1" });
yield* BetterStack.Cloud.LoadBalancerService("http", {
loadBalancerId: lb.id,
protocol: "tcp",
listenPort: 80,
destinationPort: 8080,
});

An HTTP check on /health every 10 seconds

yield* BetterStack.Cloud.LoadBalancerService("api", {
loadBalancerId: lb.id,
protocol: "http",
listenPort: 80,
destinationPort: 3000,
healthCheck: {
protocol: "http",
path: "/health",
statusCodes: "2??",
intervalSeconds: 10,
timeoutSeconds: 5,
retries: 3,
},
stickySessions: true,
});

Terminate TLS and redirect plain HTTP

yield* BetterStack.Cloud.LoadBalancerService("https", {
loadBalancerId: lb.id,
protocol: "https",
listenPort: 443,
destinationPort: 3000,
certificateIds: [certificateId],
redirectHttp: true,
});

By load balancer and id

const existing = BetterStack.Cloud.LoadBalancerService.lookup({ loadBalancerId: "42", id: "7" });

destinationPort number required

The port on the targets that traffic goes to, 1-65535.

listenPort number required

The port the service listens on, 1-65535. Can't be 8402 or 9901, which the load balancer uses itself. A tcp and a udp service can use the same port.

loadBalancerId string required

The load balancer the service belongs to (lb.id). Changing it replaces the service.

protocol "tcp" | "udp" | "http" | "https" | string required

The protocol the service listens for. - tcp: Forwards TCP connections. - http: Forwards HTTP requests. - https: Ends TLS with the service's certificates and forwards HTTP requests. An https service requires at least one certificate in certificate_ids. - udp: Forwards UDP traffic. A udp service can't use certificates, sticky_sessions, redirect_http or proxy_protocol.

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.

certificateIds string[]

The IDs of the certificates the service presents. Each certificate must be in the load balancer's team. An https service requires at least one certificate. An update replaces the whole list.

healthCheck CreateLoadBalancerServiceRequestHealthCheck

The health check of the service's targets. An update changes only the health check fields you send.

httpTimeoutSeconds number

The HTTP timeout in seconds, 5-600.

proxyProtocol "disabled" | "v1" | "v2" | string

The PROXY protocol version the targets accept, or disabled. A udp service can't use it.

redirectHttp boolean

Whether HTTP requests are redirected to this HTTPS service. Only https services can redirect.

stickyCookieLifetimeSeconds number

How long the sticky session cookie lasts, 1-86400 seconds.

stickyCookieName string

The name of the sticky session cookie, 1-64 letters, digits, underscores, dots or hyphens. Defaults to BSLBSTICKY.

stickySessions boolean

Whether a cookie sends each client to the same target. Only http and https services can use sticky sessions.

availabilityZone string always set

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

id string always set

The service's ID.

loadBalancerId string always set

The load balancer the service belongs to.

certificateIds string[]

The IDs of the certificates the service presents. Each certificate must be in the load balancer's team. An https service requires at least one certificate. An update replaces the whole list.

createdAt string

When the service was created.

destinationPort number

The port on the targets that traffic goes to, 1-65535.

healthCheck LoadBalancerServiceHealthCheck

The health check of the service's targets. An update changes only the health check fields you send.

httpTimeoutSeconds number

The HTTP timeout in seconds, 5-600.

listenPort number

The port the service listens on, 1-65535. Can't be 8402 or 9901, which the load balancer uses itself. A tcp and a udp service can use the same port.

protocol "tcp" | "udp" | "http" | "https"

The protocol the service listens for. - tcp: Forwards TCP connections. - http: Forwards HTTP requests. - https: Ends TLS with the service's certificates and forwards HTTP requests. An https service requires at least one certificate in certificate_ids. - udp: Forwards UDP traffic. A udp service can't use certificates, sticky_sessions, redirect_http or proxy_protocol.

proxyProtocol "disabled" | "v1" | "v2"

The PROXY protocol version the targets accept, or disabled. A udp service can't use it.

redirectHttp boolean

Whether HTTP requests are redirected to this HTTPS service. Only https services can redirect.

stickyCookieLifetimeSeconds number

How long the sticky session cookie lasts, 1-86400 seconds.

stickyCookieName string

The name of the sticky session cookie, 1-64 letters, digits, underscores, dots or hyphens. Defaults to BSLBSTICKY.

stickySessions boolean

Whether a cookie sends each client to the same target. Only http and https services can use sticky sessions.

targetHealth LoadBalancerServiceTargetHealthItem[]

The latest health of each target, updated about every 30 seconds.

updatedAt string

When the service was last updated.

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

id string required

The service's ID.

loadBalancerId string required

The load balancer the service belongs to.

availabilityZone string

Zone the load balancer lives in. Defaults to the credentials' zone.