Skip to content

DigitalOcean.Load Balancers reference

Source: packages/digitalocean/src/LoadBalancer.ts

A DigitalOcean regional Load Balancer in front of droplets. Forwarding rules, health checks, sticky sessions, its targets and its size update in place; region, vpcUuid and network replace it, with a new IP.

A load balancer has no tags of its own. Alchemy owns one whose name it generated or whose id it recorded; a load balancer that already has the chosen name is Unowned and needs --adopt.

const web = (name: string) =>
DigitalOcean.Droplet(name, {
region: "sfo3",
size: "s-1vcpu-1gb",
image: "ubuntu-24-04-x64",
userData: "#cloud-config\npackages: [nginx]",
});
const a = yield* web("web-a");
const b = yield* web("web-b");
const lb = yield* DigitalOcean.LoadBalancer("web", {
region: "sfo3",
forwardingRules: [
{ entryProtocol: "http", entryPort: 80, targetProtocol: "http", targetPort: 80 },
],
healthCheck: { protocol: "http", port: 80, path: "/" },
dropletIds: [a.dropletId, b.dropletId],
});
// Serve traffic at lb.ip.
const tag = yield* DigitalOcean.Tag("web", { name: "web" });
const lb = yield* DigitalOcean.LoadBalancer("web", {
region: "sfo3",
forwardingRules: [
{ entryProtocol: "http", entryPort: 80, targetProtocol: "http", targetPort: 80 },
],
tag: tag.name,
});
const cert = yield* DigitalOcean.Certificate("web-cert", {
type: "lets_encrypt",
dnsNames: ["shop.example.com"],
});
const lb = yield* DigitalOcean.LoadBalancer("web", {
region: "sfo3",
forwardingRules: [
{
entryProtocol: "https",
entryPort: 443,
targetProtocol: "http",
targetPort: 80,
certificateId: cert.certificateId,
},
],
redirectHttpToHttps: true,
tag: "web",
});