To create a new load balancer instance, send a POST request to
/v2/load_balancers
.
You can specify the Droplets that will sit behind the load balancer using one of two methods:
droplet_ids
to a list of specific Droplet IDs.tag
to the name of a tag. All Droplets with this tag applied will be
assigned to the load balancer. Additional Droplets will be automatically
assigned as they are tagged.These methods are mutually exclusive.
import os
from pydo import Client
client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
req = {
"name": "example-lb-01",
"region": "nyc3",
"forwarding_rules": [
{
"entry_protocol": "http",
"entry_port": 80,
"target_protocol": "http",
"target_port": 80
},
{
"entry_protocol": "https",
"entry_port": 443,
"target_protocol": "https",
"target_port": 443,
"tls_passthrough": True
}
],
"droplet_ids": [
3164444,
3164445
],
"project_id": "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30",
"http_idle_timeout_seconds": 60,
"firewall": {
"deny": [
"cidr:1.2.0.0/16",
"ip:2.3.4.5"
],
"allow": [
"ip:1.2.3.4",
"cidr:2.3.4.0/24"
]
}
}
resp = client.load_balancers.create(body=req)
See the API spec for this endpoint to view additional detail on responses, headers, parameters, and more.