pydo.load_balancers.create()

Description

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:

  • Set droplet_ids to a list of specific Droplet IDs.
  • Set 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.

Request Sample

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)

Responses

See the API spec for this endpoint to view additional detail on responses, headers, parameters, and more.

Accepted

Click to expand an example response for Basic Create Response.
{
  "value": {
    "load_balancer": {
      "id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
      "name": "example-lb-01",
      "ip": "104.131.186.241",
      "size": "lb-small",
      "algorithm": "round_robin",
      "status": "new",
      "created_at": "2017-02-01T22:22:58Z",
      "forwarding_rules": [
        {
          "entry_protocol": "http",
          "entry_port": 80,
          "target_protocol": "http",
          "target_port": 80,
          "certificate_id": "",
          "tls_passthrough": false
        },
        {
          "entry_protocol": "https",
          "entry_port": 443,
          "target_protocol": "https",
          "target_port": 443,
          "certificate_id": "",
          "tls_passthrough": true
        }
      ],
      "health_check": {
        "protocol": "http",
        "port": 80,
        "path": "/",
        "check_interval_seconds": 10,
        "response_timeout_seconds": 5,
        "healthy_threshold": 5,
        "unhealthy_threshold": 3
      },
      "sticky_sessions": {
        "type": "none"
      },
      "region": {
        "name": "New York 3",
        "slug": "nyc3",
        "sizes": [
          "s-1vcpu-1gb",
          "s-1vcpu-2gb",
          "s-1vcpu-3gb",
          "s-2vcpu-2gb",
          "s-3vcpu-1gb",
          "s-2vcpu-4gb",
          "s-4vcpu-8gb",
          "s-6vcpu-16gb",
          "s-8vcpu-32gb",
          "s-12vcpu-48gb",
          "s-16vcpu-64gb",
          "s-20vcpu-96gb",
          "s-24vcpu-128gb",
          "s-32vcpu-192gb"
        ],
        "features": [
          "private_networking",
          "backups",
          "ipv6",
          "metadata",
          "install_agent"
        ],
        "available": true
      },
      "tag": "",
      "droplet_ids": [
        3164444,
        3164445
      ],
      "redirect_http_to_https": false,
      "enable_proxy_protocol": false,
      "enable_backend_keepalive": false,
      "vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b",
      "disable_lets_encrypt_dns_records": false,
      "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"
        ]
      }
    }
  }
}
Click to expand an example response for SSL Termination Create Response.
{
  "value": {
    "load_balancer": {
      "id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
      "name": "example-lb-01",
      "ip": "104.131.186.241",
      "size": "lb-small",
      "algorithm": "round_robin",
      "status": "new",
      "created_at": "2017-02-01T22:22:58Z",
      "forwarding_rules": [
        {
          "entry_protocol": "https",
          "entry_port": 443,
          "target_protocol": "http",
          "target_port": 8080,
          "certificate_id": "892071a0-bb95-49bc-8021-3afd67a210bf"
        }
      ],
      "health_check": {
        "protocol": "http",
        "port": 80,
        "path": "/",
        "check_interval_seconds": 10,
        "response_timeout_seconds": 5,
        "healthy_threshold": 5,
        "unhealthy_threshold": 3
      },
      "sticky_sessions": {
        "type": "none"
      },
      "region": {
        "name": "New York 3",
        "slug": "nyc3",
        "sizes": [
          "s-1vcpu-1gb",
          "s-1vcpu-2gb",
          "s-1vcpu-3gb",
          "s-2vcpu-2gb",
          "s-3vcpu-1gb",
          "s-2vcpu-4gb",
          "s-4vcpu-8gb",
          "s-6vcpu-16gb",
          "s-8vcpu-32gb",
          "s-12vcpu-48gb",
          "s-16vcpu-64gb",
          "s-20vcpu-96gb",
          "s-24vcpu-128gb",
          "s-32vcpu-192gb"
        ],
        "features": [
          "private_networking",
          "backups",
          "ipv6",
          "metadata",
          "install_agent"
        ],
        "available": true
      },
      "tag": "",
      "droplet_ids": [
        3164444,
        3164445
      ],
      "redirect_http_to_https": false,
      "enable_proxy_protocol": false,
      "enable_backend_keepalive": false,
      "vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b",
      "disable_lets_encrypt_dns_records": false
    }
  }
}
Click to expand an example response for Create Response Using Droplet Tag.
{
  "value": {
    "load_balancer": {
      "id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
      "name": "example-lb-01",
      "ip": "104.131.186.241",
      "size": "lb-small",
      "algorithm": "round_robin",
      "status": "new",
      "created_at": "2017-02-01T22:22:58Z",
      "forwarding_rules": [
        {
          "entry_protocol": "https",
          "entry_port": 443,
          "target_protocol": "http",
          "target_port": 8080,
          "certificate_id": "892071a0-bb95-49bc-8021-3afd67a210bf"
        }
      ],
      "health_check": {
        "protocol": "http",
        "port": 80,
        "path": "/",
        "check_interval_seconds": 10,
        "response_timeout_seconds": 5,
        "healthy_threshold": 5,
        "unhealthy_threshold": 3
      },
      "sticky_sessions": {
        "type": "none"
      },
      "region": {
        "name": "New York 3",
        "slug": "nyc3",
        "sizes": [
          "s-1vcpu-1gb",
          "s-1vcpu-2gb",
          "s-1vcpu-3gb",
          "s-2vcpu-2gb",
          "s-3vcpu-1gb",
          "s-2vcpu-4gb",
          "s-4vcpu-8gb",
          "s-6vcpu-16gb",
          "s-8vcpu-32gb",
          "s-12vcpu-48gb",
          "s-16vcpu-64gb",
          "s-20vcpu-96gb",
          "s-24vcpu-128gb",
          "s-32vcpu-192gb"
        ],
        "features": [
          "private_networking",
          "backups",
          "ipv6",
          "metadata",
          "install_agent"
        ],
        "available": true
      },
      "tag": "prod:web",
      "droplet_ids": [
        3164444,
        3164445
      ],
      "redirect_http_to_https": false,
      "enable_proxy_protocol": false,
      "enable_backend_keepalive": false,
      "vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b",
      "disable_lets_encrypt_dns_records": false,
      "project_id": "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30"
    }
  }
}
Click to expand an example response for Sticky Sessions and Custom Health Check.
{
  "value": {
    "load_balancer": {
      "id": "4de7ac8b-495b-4884-9a69-1050c6793cd6",
      "name": "example-lb-01",
      "ip": "104.131.186.241",
      "size": "lb-small",
      "algorithm": "round_robin",
      "status": "new",
      "created_at": "2017-02-01T22:22:58Z",
      "forwarding_rules": [
        {
          "entry_protocol": "https",
          "entry_port": 443,
          "target_protocol": "http",
          "target_port": 8080,
          "certificate_id": "892071a0-bb95-49bc-8021-3afd67a210bf"
        }
      ],
      "health_check": {
        "protocol": "http",
        "port": 8080,
        "path": "/health",
        "check_interval_seconds": 10,
        "response_timeout_seconds": 5,
        "healthy_threshold": 5,
        "unhealthy_threshold": 3
      },
      "sticky_sessions": {
        "type": "cookies",
        "cookie_name": "LB_COOKIE",
        "cookie_ttl_seconds": 300
      },
      "region": {
        "name": "New York 3",
        "slug": "nyc3",
        "sizes": [
          "s-1vcpu-1gb",
          "s-1vcpu-2gb",
          "s-1vcpu-3gb",
          "s-2vcpu-2gb",
          "s-3vcpu-1gb",
          "s-2vcpu-4gb",
          "s-4vcpu-8gb",
          "s-6vcpu-16gb",
          "s-8vcpu-32gb",
          "s-12vcpu-48gb",
          "s-16vcpu-64gb",
          "s-20vcpu-96gb",
          "s-24vcpu-128gb",
          "s-32vcpu-192gb"
        ],
        "features": [
          "private_networking",
          "backups",
          "ipv6",
          "metadata",
          "install_agent"
        ],
        "available": true
      },
      "tag": "prod:web",
      "droplet_ids": [
        3164444,
        3164445
      ],
      "redirect_http_to_https": false,
      "enable_proxy_protocol": false,
      "enable_backend_keepalive": false,
      "vpc_uuid": "c33931f2-a26a-4e61-b85c-4e95a2ec431b",
      "disable_lets_encrypt_dns_records": false,
      "project_id": "9cc10173-e9ea-4176-9dbc-a4cee4c4ff30"
    }
  }
}

Unauthorized

Click to expand an example response.
{
  "id": "unauthorized",
  "message": "Unable to authenticate you."
}

API Rate limit exceeded

Click to expand an example response.
{
  "id": "too_many_requests",
  "message": "API Rate limit exceeded."
}

Server error.

Click to expand an example response.
{
  "id": "server_error",
  "message": "Unexpected server-side error"
}

Unexpected error

Click to expand an example response.
{
  "id": "example_error",
  "message": "some error message"
}