Updated on 2025-09-22 GMT+08:00

Creating a Load Balancer

Function

This API is used to create a dedicated load balancer.

When you create a load balancer, note the following:

  • Specify vip_subnet_cidr_id if you want to bind a private IPv4 address to the load balancer.

  • Specify publicip and either vpc_id or vip_subnet_cidr_id if you want to bind a new IPv4 EIP to the load balancer.

  • Specify publicip_ids and either vpc_id or vip_subnet_cidr_id if you want to bind an existing IPv4 EIP to the load balancer.

  • Specify ipv6_vip_virsubnet_id if you want to bind a private IPv6 address to the load balancer.

  • Specify both ipv6_vip_virsubnet_id and ipv6_bandwidth if you want to bind a public IPv6 address to the load balancer.

  • Specify l4_flavor_id if you want to create a network load balancer and l7_flavor_id to create an application load balancer. Specify both l4_flavor_id and l7_flavor_id if you want to create a load balancer that can work at both Layer 4 and Layer 7.

  • If prepaid_options is not specified, pay-per-use load balancers will be created, which are billed by fixed specifications or elastic specifications you have selected for l4_flavor_id and l7_flavor_id when creating the load balancer.

Constraints

There are some constraints when you create a load balancer:

  • vpc_id, vip_subnet_cidr_id, and ipv6_vip_virsubnet_id cannot be left blank at the same time.

  • ip_target_enable specifies whether to enable IP as a Backend. If you set it to true, you can associate servers in a VPC connected through a VPC peering connection, in a VPC connected through a cloud connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using server IP addresses. If you set it to false, the load balancer and the backend servers must be in the same VPC.

  • admin_state_up must be true.

  • provider must be set to vlb.

  • elb_virsubnet_ids indicates the subnets that support IPv4/IPv6 dual stack or only IPv4. If only IPv4 subnets are supported, ipv6_vip_virsubnet_id must be left blank.

  • You can unbind the EIP only on the ELB console. Locate the load balancer in the load balancer list and click More > Unbind EIP in the Operation column.

  • publicip_ids and publicip cannot be specified at the same time. Set either publicip_ids to bind an existing EIP to the load balancer, or publicip to bind a new EIP to the load balancer, or neither of them.

  • If you want to add the load balancer to an existing shared bandwidth, you must specify the ID of the shared bandwidth. If you want the load balancer to use a new dedicated bandwidth, charge_mode, share_type, and size are required.

Calling Method

For details, see Calling APIs.

URI

POST /v3/{project_id}/elb/loadbalancers

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Constraints: N/A

Range: The value can contain a maximum of 32 characters, including digits and lowercase letters.

Default value: N/A

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

Definition: Specifies the token used for IAM authentication.

Constraints: N/A

Range: N/A

Default value: N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

loadbalancer

Yes

CreateLoadBalancerOption object

Definition: Specifies the parameters for creating a load balancer.

Constraints: N/A

Table 4 CreateLoadBalancerOption

Parameter

Mandatory

Type

Description

project_id

No

String

Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID.

Constraints: N/A

Range: The value can contain a maximum of 32 characters, including digits and lowercase letters.

Default value: N/A

NOTE:
This parameter is invalid. The project ID in the URL is used.

name

No

String

Definition: Specifies the load balancer name.

Constraints: N/A

Range: The value can contain a maximum of 255 Unicode characters, including letters and more. It can be left blank.

Default value: N/A

description

No

String

Definition: Provides supplementary information about the load balancer.

Constraints: N/A

Range: The value can contain a maximum of 255 Unicode characters, including letters and more. It can be left blank.

Default value: N/A

vip_address

No

String

Definition: Specifies the private IPv4 address of the load balancer. The IP address must be from the IPv4 subnet where the load balancer resides and should not be used by other services.

Constraints:

  • vip_subnet_cidr_id is also required if vip_address is specified.

  • If only vip_subnet_cidr_id is specified, the system will automatically assign a private IPv4 address to the load balancer.

  • If neither vip_address nor vip_subnet_cidr_id is specified, no private IPv4 address will be assigned, and the value of vip_address will be null.

Range: The IP address must be in [0-255].[0-255].[0-255].[0-255] format, for example, 192.168.1.1.

Default value: N/A

vip_subnet_cidr_id

No

String

Definition: Specifies the ID of the IPv4 subnet where the load balancer is located. This subnet is also called the frontend subnet.

Constraints:

  • This parameter is mandatory if you need to create a load balancer with a private IPv4 address. You can query parameter neutron_subnet_id in the response by calling the VPC API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets).

  • vpc_id, vip_subnet_cidr_id, and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id.

  • The subnet specified by vip_subnet_cidr_id must be in the VPC specified by vpc_id if both vpc_id and vip_subnet_cidr_id are specified.

Range: The ID must be in UUID format and can contain up to 36 characters.

Default value: N/A

ipv6_vip_virsubnet_id

No

String

Definition: Specifies the ID of the IPv6 subnet where the load balancer is located. This subnet is also called the frontend subnet.

Constraints:

  • This parameter is mandatory if you need to create a load balancer with a private IPv6 address. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets).

  • vpc_id, vip_subnet_cidr_id, and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id.

  • IPv6 must have been enabled for the subnet where the load balancer resides.

Range: The ID must be in UUID format and can contain up to 36 characters.

Default value: N/A

provider

No

String

Definition: Specifies the provider of the load balancer.

Constraints: N/A

Range: The value can only be vlb and does not need to be specified.

Default value: vlb

l4_flavor_id

No

String

Definition: Specifies the ID of a flavor at Layer 4.

Constraints:

  • You can query parameter id in the response by calling the API (GET https://{ELB_Endpoint}/v3/{project_id}/elb/flavors?type=L4).

  • If neither l4_flavor_id nor l7_flavor_id is specified, the default flavor is used. The default flavor varies by site.

  • If the flavor type is L4, the load balancer uses the fixed flavors and will be billed by the flavor you select.

  • If the flavor type is L4_elastic_max, the load balancer uses the elastic flavors and will be billed by how many LCUs you use.

Range: The ID must be in UUID format and can contain up to 36 characters.

Default value: N/A

l7_flavor_id

No

String

Definition: Specifies the ID of a flavor at Layer 7.

Constraints:

  • You can query parameter id in the response by calling the API (GET https://{ELB_Endpoint}/v3/{project_id}/elb/flavors?type=L7).

  • If neither l4_flavor_id nor l7_flavor_id is specified, the default flavor is used. The default flavor varies by site.

  • If the flavor type is L7, the load balancer uses the fixed flavors and will be billed by the flavor you select.

  • If the flavor type is L7_elastic_max, the load balancer uses the elastic flavors and will be billed by how many LCUs you use.

Range: The ID must be in UUID format and can contain up to 36 characters.

Default value: N/A

guaranteed

No

Boolean

Definition: Specifies whether to create a shared or dedicated load balancer.

Currently, the value can only be true. If the value is set to false, 400 Bad Request will be returned.

Range:

  • true: Dedicated load balancers will be created.

  • false: Shared load balancers will be created.

Default value: true

vpc_id

No

String

Definition: Specifies the ID of the VPC where the load balancer is located.

Constraints:

  • You can query parameter id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/vpcs).

  • vpc_id, vip_subnet_cidr_id, and ipv6_vip_virsubnet_id cannot be left blank at the same time. The subnet specified by vip_subnet_cidr_id and the subnet specified by ipv6_vip_virsubnet_id must be in the VPC specified by vpc_id.

Range: The ID must be in UUID format and can contain up to 36 characters.

Default value: N/A

availability_zone_list

Yes

Array of strings

Definition: Specifies the list of AZs where the load balancers are created.

You can query the AZs by calling the API (GET https://{ELB_Endpoint}/v3/{project_id}/elb/availability-zones). Select one or more AZs in the same set.

Constraints: N/A

Range: N/A

Default value: N/A

NOTE:
If disaster recovery is required, you are advised to select multiple AZs.

enterprise_project_id

No

String

Definition: Specifies the ID of the enterprise project. If no enterprise project ID is specified during resource creation, 0 is returned, indicating that the resource belongs to the default enterprise project.

Constraints: The enterprise project ID cannot be "", 0, or an enterprise project ID that does not exist.

Range: N/A

Default value: 0

tags

No

Array of Tag objects

Definition: Specifies the tags added to the load balancer. Example: "tags":[{"key":"my_tag","value":"my_tag_value"}]

Constraints: N/A

admin_state_up

No

Boolean

Definition: Specifies whether the load balancer is enabled.

Constraints: N/A

Range:

  • true: enabled

  • false: disabled

Default value: true

billing_info

No

String

Definition: Provides resource billing information.

Constraints: N/A

Range:

  • If the value is left blank, the resource is billed on a pay-per-use basis.

Default value: N/A

This parameter is unsupported. Please do not use it.

ipv6_bandwidth

No

BandwidthRef object

Definition: Specifies the ID of the bandwidth.

Constraints:

  • This parameter is available only when you create or update a load balancer with a public address.

  • If you bind a new EIP to the load balancer and specify a shared bandwidth, this EIP will be added to the shared bandwidth.

publicip_ids

No

Array of strings

Definition: Specifies the IDs of the EIPs bound to the load balancer.

Constraints:

  • Only the first EIP in the array will be bound.

publicip

No

CreateLoadBalancerPublicIpOption object

Definition: Specifies the request parameters for binding a new EIP to the load balancer.

Constraints: N/A

elb_virsubnet_ids

No

Array of strings

Definition: (OpenStack Neutron API) Specifies the network IDs of backend subnets where the load balancers work. A load balancer uses IP addresses in the backend subnet to communicate with backend servers (such as in health check and FullNAT scenarios).

You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets?vpc_id=xxxx).

Constraints:

  • The backend subnet must in the VPC where the load balancer works.

  • You need to specify a backend subnet for the load balancer and add rules to the security group associated with the backend server to allow access from the backend subnet.

  • If there is more than one subnet, the first subnet in the list will be used to assign IP addresses.

  • If this parameter is not specified, the network IDs will be used based on the following rules:

    • If IPv6 is enabled for a load balancer, the network IDs of subnets specified in ipv6_vip_virsubnet_id will be used.

    • If IPv6 is not enabled for a load balancer, the network IDs of subnets specified in vip_subnet_cidr_id will be used.

    • If a load balancer only works on the public network, any subnet in the VPC where the load balancer is deployed will be used. The subnet with the most available IP addresses is preferred.

  • A load balancer uses IP addresses in the backend subnet to communicate with backend servers (such as in health check, and FullNAT scenarios). To prevent traffic from being blocked by the security groups associated with backend servers, add security group rules to allow access from the backend subnet of the load balancer to backend servers.

  • In the elastic scaling scenario, the reserved IP addresses may change. It is recommended that you should add security group rules to allow access from the backend subnet of the load balancer instead of only allowing certain IP addresses.

  • You are advised to use a dedicated subnet with sufficient IP addresses for easier O&M.

Range: N/A

Default value: N/A

ip_target_enable

No

Boolean

Definition: Specifies whether to add backend servers that are not in the load balancer's VPC.

If you set it to true, you can associate servers in a VPC connected through a VPC peering connection, in a VPC connected through a cloud connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using server IP addresses.

Constraints:

  • This function cannot be disabled once it is enabled.

  • If you want to enable IP as a Backend for a load balancer in a shared VPC, ensure that a VPC peering connection has been created to connect the VPCs. Otherwise, the communication will fail.

  • This function is supported only by dedicated load balancers.

Range:

  • true: This option will be enabled.

  • false: This option will be disabled.

Default value: false

deletion_protection_enable

No

Boolean

Definition: Specifies whether to enable deletion protection for the load balancer.

Constraints: Before deleting a load balancer, you need to disable deletion protection first.

Range:

  • false: This option will not be enabled.

  • true: This option will be enabled.

Default value: false

prepaid_options

No

PrepaidCreateOption object

Definition: Specifies the prepaid billing configuration for creating a load balancer. If this structure is passed, a prepaid load balancer is created.

Constraints: N/A

This parameter is unsupported. Please do not use it.

autoscaling

No

CreateLoadbalancerAutoscalingOption object

Definition: Specifies information about elastic scaling. If elastic scaling is enabled, the load balancer flavors can be automatically adjusted based on incoming traffic.

Constraints:

  • This parameter is only available for whitelisted users.

  • If elastic scaling is enabled, l4_flavor_id indicates the ID of the maximum elastic flavor at Layer 4. l7_flavor_id indicates the ID of the maximum elastic flavor at Layer 7.

NOTE:
This parameter has been deprecated, but is retained for compatibility purposes. Using this parameter is not recommended. If this parameter is specified, the load balancer with minimum flavors will be created and you will be billed for the minimum flavors.

waf_failure_action

No

String

Definition: Specifies traffic distributing policies when the WAF is faulty.

Constraints: This parameter takes effect only when WAF is enabled for the load balancer.

Range:

  • discard: Traffic will not be distributed.

  • forward: Traffic will be distributed to the backend servers.

Default value: forward

protection_status

No

String

Definition: Specifies the protection status. This parameter is used to prevent resources from being modified by accident on the console. If this parameter is set to consoleProtection, you cannot modify resource settings on the console.

Constraints: You can call APIs to modify resource attributes, such as resource tags. This improves user experience on the console, for example, preventing accidental modification.

Range:

  • nonProtection: The resource is not protected.

  • consoleProtection: Modification is not allowed on the console.

Default value: nonProtection

protection_reason

No

String

Definition: Specifies why modification protection is enabled.

Constraints: This parameter is valid only when protection_status is set to consoleProtection.

Range: The value can contain a maximum of 255 Unicode characters, excluding angle brackets (<>).

Default value: N/A

charge_mode

No

String

Definition: Specifies the charge mode of the load balancer.

Constraints: You are not recommended to specify this parameter. The charge mode will be selected based on the value you have specified for l4_flavor_id or l7_flavor_id.

Range:

  • flavor: billed by the fixed flavor you select.

  • lcu: billed by how many LCUs you have used.

Default value:

  • If this parameter is not specified during the creation of a shared load balancer, flavor is selected by default.

  • If you create a dedicated load balancer, this parameter is ignored. The charge mode will be selected based on the value you have specified for l4_flavor_id or l7_flavor_id.

ipv6_vip_address

No

String

Definition: Specifies the IPv6 address used by the load balancer.

Constraints:

  • The IPv6 address must be one in the subnet defined by ipv6_vip_virsubnet_id.

  • Subnets defined by elb_virsubnet_ids must support IPv4/IPv6 dual stack.

Range: N/A

Default value: N/A

Table 5 Tag

Parameter

Mandatory

Type

Description

key

No

String

Definition: Specifies the tag key.

Range: N/A

value

No

String

Definition: Specifies the tag value.

Range: N/A

Table 6 BandwidthRef

Parameter

Mandatory

Type

Description

id

Yes

String

Definition: Specifies the ID of the shared bandwidth.

Constraints: N/A

Range: N/A

Default value: N/A

Table 7 CreateLoadBalancerPublicIpOption

Parameter

Mandatory

Type

Description

ip_version

No

Integer

Definition: Specifies the IP address version.

Constraints: N/A

Range:

  • 4: IPv4 addresses

  • 6: IPv6 addresses

Default value: 4

network_type

Yes

String

Definition: Specifies the EIP type. The default value is 5_bgp. For more information, see the API for assigning an EIP in the Virtual Private Cloud API Reference.

Range: 5_bgp

Default value: 5_bgp

billing_info

No

String

Definition: Provides billing information about the EIP.

Constraints:

  • If the value is left blank, the resource is billed on a pay-per-use basis.

Range: N/A

Default value: N/A

This parameter is unsupported. Please do not use it.

description

No

String

Definition: Provides supplementary information about the EIP.

Constraints: N/A

Range: N/A

Default value: N/A

bandwidth

Yes

CreateLoadBalancerBandwidthOption object

Definition: Provides supplementary information about the bandwidth.

Constraints: N/A

Table 8 CreateLoadBalancerBandwidthOption

Parameter

Mandatory

Type

Description

name

No

String

Definition: Specifies the bandwidth name.

Constraints:

  • This parameter is mandatory if share_type is set to PER.

  • This parameter will be ignored if the bandwidth reference has a specific ID.

Range: The value can contain 1 to 64 characters, including digits, letters, underscores (_), hyphens (-), and periods (.).

Default value: N/A

size

No

Integer

Definition: Specifies the bandwidth size.

Constraints:

  • This parameter is mandatory if id is set to null.

  • The minimum increment for bandwidth adjustment varies by bandwidth range. The details are as follows:

    • The minimum increment is 1 Mbit/s if the bandwidth range is from 0 Mbit/s to 300 Mbit/s.

    • The minimum increment is 50 Mbit/s if the bandwidth range is from 301 Mbit/s to 1,000 Mbit/s.

    • The minimum increment is 500 Mbit/s if the bandwidth is greater than 1,000 Mbit/s.

Range: The default value ranges from 1 Mbit/s to 2,000 Mbit/s, which may vary by region and can be viewed on the management console.

Default value: N/A

charge_mode

No

String

Definition: Specifies how the bandwidth used by the EIP is billed.

Constraints: This parameter is mandatory if id is set to null.

Range:

  • bandwidth: billed by bandwidth

  • traffic: billed by traffic

Default value: N/A

share_type

No

String

Definition: Specifies the bandwidth type.

Constraints:

  • This parameter is mandatory when id is set to null. It will be ignored if the value of id is not null.

  • The bandwidth ID must be specified if the bandwidth type is set to WHOLE.

  • The bandwidth type cannot be WHOLE for IPv6 EIPs.

Range:

  • PER: dedicated bandwidths

  • WHOLE: shared bandwidths

Default value: N/A

billing_info

No

String

Definition: Provides resource billing information.

Constraints: N/A

Range: N/A

Default value: N/A

This parameter is unsupported. Please do not use it.

id

No

String

Definition: Specifies the ID of the shared bandwidth. An existing shared bandwidth is used.

Constraints: The ID must be an existing shared bandwidth ID. There is no need to specify this parameter if the billing mode is yearly/monthly. This parameter will be ignored if it is left blank.

Range: N/A

Default value: N/A

Table 9 PrepaidCreateOption

Parameter

Mandatory

Type

Description

period_type

Yes

String

Definition: Specifies the subscription period type.

Constraints: N/A

Range:

  • month: monthly subscription

  • year: yearly subscription

Default value: N/A

period_num

No

Integer

Definition: Specifies the number of subscription periods.

Constraints: N/A

Range:

  • The value ranges from 1 to 9, if period_type is set to month.

  • The value ranges from 1 to 3, if period_type is set to year.

Default value: N/A

auto_renew

No

Boolean

Definition: Specifies whether to enable automatic renewal.

Constraints: N/A

Range:

  • true: Enable automatic renewal.

  • false (default): Disable automatic renewal.

Default value: N/A

auto_pay

No

Boolean

Definition: Specifies whether an order is automatically paid using your account balance without manual operations.

Constraints: If you use the automatic payment mode, only your account balance can be used. If you want to use a voucher, do not use the automatic payment mode, and select the voucher for the payment in the Billing Center.

Range:

  • true: The order will be automatically paid.

  • false: The order will not be automatically paid.

Default value: N/A

Table 10 CreateLoadbalancerAutoscalingOption

Parameter

Mandatory

Type

Description

enable

Yes

Boolean

Definition: Specifies whether to enable elastic scaling for the load balancer.

Constraints: N/A

Range:

  • true: This option will be enabled.

  • false: This option will be disabled.

Default value: N/A

min_l7_flavor_id

No

String

Definition: Specifies the ID of the minimum elastic flavor at Layer 7.

Constraints: N/A

Range: N/A

Default value: N/A

Response Parameters

Status code: 201

Table 11 Response body parameters

Parameter

Type

Description

loadbalancer

LoadBalancer object

Definition: Specifies the load balancer.

request_id

String

Definition: Specifies the request ID.

Range: The value is automatically generated, and can contain characters including digits, lowercase letters, and hyphens (-).

Table 12 LoadBalancer

Parameter

Type

Description

id

String

Definition: Specifies the load balancer ID.

Range: N/A

description

String

Definition: Provides supplementary information about the load balancer.

Range: N/A

provisioning_status

String

Definition: Specifies the provisioning status of the load balancer.

Range:

  • ACTIVE: in use

  • PENDING_DELETE: deleting

admin_state_up

Boolean

Definition: Specifies whether the load balancer is enabled.

Range:

  • true: enabled

  • false: disabled

provider

String

Definition: Specifies the provider of the load balancer. The value is fixed to vlb.

Range: N/A

pools

Array of PoolRef objects

Definition: Lists the IDs of backend server groups associated with the load balancer.

listeners

Array of ListenerRef objects

Definition: Lists the IDs of listeners associated with the load balancer.

operating_status

String

Definition: Specifies the operating status of the load balancer.

Range:

  • ONLINE: The load balancer is online.

  • FROZEN: The load balancer is frozen.

name

String

Definition: Specifies the load balancer name.

Range: N/A

project_id

String

Definition: Specifies the ID of the project where the load balancer is used.

Range: N/A

vip_subnet_cidr_id

String

Definition: Specifies the ID of the IPv4 subnet where the load balancer is located. This subnet is also called the frontend subnet.

Range: N/A

vip_address

String

Definition: Specifies the private IPv4 address of the load balancer.

Range: N/A

vip_port_id

String

Definition: Specifies the ID of the port bound to the private IPv4 address of the load balancer.

Range: N/A

tags

Array of Tag objects

Definition: Specifies the tags added to the load balancer.

created_at

String

Definition: Specifies the time when the load balancer was created.

Range:

The value must be in the format of yyyy-MM-dd'T'HH:mm:ss'Z'.

updated_at

String

Definition: Specifies the time when the load balancer was updated.

Range:

The value must be in the format of yyyy-MM-dd'T'HH:mm:ss'Z'.

guaranteed

Boolean

Definition: Specifies whether the load balancer is a dedicated load balancer.

Range:

  • false: The load balancer is a shared load balancer.

  • true: The load balancer is a dedicated load balancer.

vpc_id

String

Definition: Specifies the ID of the VPC where the load balancer is located.

Range: N/A

eips

Array of EipInfo objects

Definition: Specifies the EIP bound to the load balancer.

NOTE:
This parameter has the same meaning as publicips.

ipv6_vip_address

String

Definition: Specifies the IPv6 address of the load balancer.

Range: N/A

ipv6_vip_virsubnet_id

String

Definition: Specifies the ID of the IPv6 subnet where the load balancer is located. This subnet is also called the frontend subnet.

Range: N/A

ipv6_vip_port_id

String

Definition: Specifies the ID of the port bound to the IPv6 address of the load balancer.

Range: N/A

availability_zone_list

Array of strings

Definition: Specifies the list of AZs where the load balancers are created.

Range: N/A

enterprise_project_id

String

Definition: Specifies the ID of the enterprise project.

Range:

  • 0: The resource belongs to the default enterprise project.

  • A string in UUID format indicates a non-default enterprise project.

billing_info

String

Definition: Provides resource billing information.

Range:

  • If the value is left blank, the resource is billed on a pay-per-use basis.

This parameter is unsupported. Please do not use it.

l4_flavor_id

String

Definition: Specifies the ID of a flavor at Layer 4.

If the current load balancer is an elastic flavor instance, this parameter defines the maximum elastic flavor at Layer 4.

Range: N/A

l4_scale_flavor_id

String

Definition: Specifies the ID of an elastic flavor at Layer 4.

Range: N/A

NOTE:
This parameter has been discarded. Do not use it.

l7_flavor_id

String

Definition: Specifies the ID of a flavor at Layer 7.

If the current load balancer is an elastic flavor instance, this parameter defines the maximum elastic flavor at Layer 7.

Range: N/A

l7_scale_flavor_id

String

Definition: Specifies the ID of an elastic flavor at Layer 7.

Range: N/A

NOTE:
This parameter has been discarded. Do not use it.

gw_flavor_id

String

Definition: Specifies the flavor ID of the gateway load balancer.

Range: N/A

This parameter is unsupported. Please do not use it.

loadbalancer_type

String

Definition: Specifies the load balancer type.

Range:

  • gateway: gateway load balancers

  • null: other types of load balancers

This parameter is unsupported. Please do not use it.

publicips

Array of PublicIpInfo objects

Definition: Specifies the EIP bound to the load balancer.

NOTE:
This parameter has the same meaning as eips.

global_eips

Array of GlobalEipInfo objects

Definition: Specifies the global EIP bound to the load balancer.

elb_virsubnet_ids

Array of strings

Definition: Specifies the network IDs of subnets on the downstream plane.

Range: N/A

elb_virsubnet_type

String

Definition: Specifies the type of the subnet on the downstream plane.

Range:

  • ipv4: IPv4 subnets

  • dualstack: subnets that support IPv4/IPv6 dual stack

ip_target_enable

Boolean

Definition: Specifies whether to add backend servers that are not in the load balancer's VPC.

If you set it to true, you can associate servers in a VPC connected through a VPC peering connection, in a VPC connected through a cloud connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using server IP addresses.

Range:

  • true: This option will be enabled.

  • false: This option will be disabled.

frozen_scene

String

Definition: Specifies the scenario where the load balancer is frozen.

If there are multiple scenarios, separate them with commas (,).

Range:

  • POLICE: The load balancer is frozen due to security reasons.

  • ILLEGAL: The load balancer is frozen due to violation of laws and regulations.

  • VERIFY: Your account has not completed real-name authentication.

  • PARTNER: The load balancer is frozen by the partner.

  • AREAR: The load balancer is frozen due to arrears.

deletion_protection_enable

Boolean

Definition: Specifies whether to enable deletion protection. This parameter is returned only when the deletion protection is enabled in the current region.

Range:

  • false: This option will be disabled.

  • true: This option will be enabled.

autoscaling

AutoscalingRef object

Definition: Specifies information about elastic scaling. If elastic scaling is enabled, the load balancer flavors can be automatically adjusted based on incoming traffic.

NOTE:
This parameter has been deprecated, but is retained for compatibility purposes. Using this parameter is not recommended. If this parameter is specified, the load balancer with minimum flavors will be created and you will be billed for the minimum flavors.

public_border_group

String

Definition: Specifies the public border group.

Range:

  • center: public border group of the central site

  • Edge site name: public border group of an edge site

charge_mode

String

Definition: Specifies the charge mode of the load balancer.

Range:

  • flavor: billed by the fixed flavor you select.

  • lcu: billed by how many LCUs you have used.

  • Null: If it is a shared load balancer, it is free. If it is a dedicated load balancer, it will be billed by the fixed flavor you select.

This parameter is unsupported. Please do not use it.

service_lb_mode

String

Definition: Specifies load balancer mode.

Range:

  • lb: Cross-tenant access is not supported.

  • ep: Cross-tenant access is supported.

This parameter is unsupported. Please do not use it.

instance_type

String

Definition: Specifies the internal service to which the load balancer belongs.

Range: N/A

This parameter is unsupported. Please do not use it.

instance_id

String

Definition: Specifies the ID of the instance with which the load balancer is associated.

Range: N/A

This parameter is unsupported. Please do not use it.

proxy_protocol_extensions

Array of ProxyProtocolExtension objects

Definition: Specifies the proxy protocol extension.

This parameter is unsupported. Please do not use it.

waf_failure_action

String

Definition: Specifies traffic distributing policies when the WAF is faulty.

Range: discard indicates traffic will not be distributed. forward indicates traffic will be distributed to the default backend servers.

protection_status

String

Definition: Specifies the protection status.

Range:

  • nonProtection: The resource is not protected.

  • consoleProtection: Modification is not allowed on the console.

protection_reason

String

Definition: Specifies why modification protection is enabled.

Range: The value can contain a maximum of 255 Unicode characters, excluding angle brackets (<>).

log_group_id

String

Definition: Specifies the ID of the log group that is associated with the load balancer.

Range: N/A

log_topic_id

String

Definition: Specifies the ID of the log topic that is associated with the load balancer.

Range: N/A

custom_qos_limit

CustomQosLimit object

Definition: Specifies the rate limit information of the ELB flavors.

Range: N/A

This parameter is unsupported. Please do not use it.

Table 13 PoolRef

Parameter

Type

Description

id

String

Definition: Specifies the backend server group ID.

Range: N/A

Table 14 ListenerRef

Parameter

Type

Description

id

String

Definition: Specifies the listener ID.

Range: N/A

Table 15 Tag

Parameter

Type

Description

key

String

Definition: Specifies the tag key.

Range: N/A

value

String

Definition: Specifies the tag value.

Range: N/A

Table 16 EipInfo

Parameter

Type

Description

eip_id

String

Definition: Specifies the EIP ID.

Range: N/A

eip_address

String

Definition: Specifies the EIP.

Range: N/A

ip_version

Integer

Definition: Specifies the IP address version.

Range:

  • 4: IPv4 addresses

  • 6: IPv6 addresses

Table 17 PublicIpInfo

Parameter

Type

Description

publicip_id

String

Definition: Specifies the EIP ID.

Range: N/A

publicip_address

String

Definition: Specifies the EIP.

Range: N/A

ip_version

Integer

Definition: Specifies the IP address version.

Range:

  • 4: IPv4 address

  • 6: IPv6 address

Table 18 GlobalEipInfo

Parameter

Type

Description

global_eip_id

String

Definition: Specifies the ID of the global EIP.

Range: N/A

global_eip_address

String

Definition: Specifies the global EIP.

Range: N/A

ip_version

Integer

Definition: Specifies the IP address version.

Range:

  • 4: IPv4 addresses

  • 6: IPv6 addresses

Table 19 AutoscalingRef

Parameter

Type

Description

enable

Boolean

Definition: Specifies whether to enable elastic scaling for the load balancer.

Range:

  • true: This option will be enabled.

  • false: This option will be disabled.

min_l7_flavor_id

String

Definition: Specifies the ID of the minimum elastic flavor at Layer 7.

Range: N/A

Table 20 ProxyProtocolExtension

Parameter

Type

Description

vip_address

String

Definition: Specifies the IPv4 address.

Constraints: N/A

Range: N/A

Default value: N/A

ipv6_vip_address

String

Definition: Specifies the IPv6 address.

Constraints: N/A

Range: N/A

Default value: N/A

extension

Extension object

Definition: Specifies the proxy protocol extension.

Constraints: N/A

Table 21 Extension

Parameter

Type

Description

ep_id

String

Definition: Specifies the VPC endpoint ID.

Constraints: N/A

Range: N/A

Default value: N/A

ep_service_id

String

Definition: Specifies the VPC endpoint service ID.

Constraints: N/A

Range: N/A

Default value: N/A

Table 22 CustomQosLimit

Parameter

Type

Description

l4

L4Limit object

Definition: Specifies the rate limit information of the ELB flavors at Layer 4.

l7

L7Limit object

Definition: Specifies the rate limit information of the ELB flavors at Layer 7.

Table 23 L4Limit

Parameter

Type

Description

connection

Integer

Definition: Specifies the maximum number of concurrent connections at Layer 4.

Range: N/A

cps

Integer

Definition: Specifies the maximum number of new connections at Layer 4.

Range: N/A

Table 24 L7Limit

Parameter

Type

Description

connection

Integer

Definition: Specifies the maximum number of concurrent connections at Layer 7.

Range: N/A

cps

Integer

Definition: Specifies the maximum number of new connections at Layer 7.

Range: N/A

Example Requests

  • Example 1: Creating a load balancer with a private IPv4 address

    POST https://{ELB_Endpoint}/v3/060576798a80d5762fafc01a9b5eedc7/elb/loadbalancers
    
    {
      "loadbalancer" : {
        "name" : "loadbalancer",
        "description" : "simple lb",
        "vip_subnet_cidr_id" : "1992ec06-f364-4ae3-b936-6a8cc24633b7",
        "admin_state_up" : true,
        "availability_zone_list" : [ "AZ1" ]
      }
    }
  • Example 2: Creating a load balancer with an IPv4 EIP

    POST https://{ELB_Endpoint}/v3/060576782980d5762f9ec014dd2f1148/elb/loadbalancers
    
    {
      "loadbalancer" : {
        "vip_subnet_cidr_id" : "e6e9271d-aef4-48f0-a93a-ccc7b09032c1",
        "availability_zone_list" : [ "AZ1" ],
        "admin_state_up" : true,
        "publicip" : {
          "network_type" : "5_bgp",
          "bandwidth" : {
            "size" : 2,
            "share_type" : "PER",
            "charge_mode" : "bandwidth",
            "name" : "bandwidth_test"
          }
        },
        "name" : "elb_eip-test"
      }
    }

Example Responses

Status code: 201

Successful request.

{
  "loadbalancer" : {
    "name" : "my_loadbalancer",
    "id" : "29cc669b-3ac8-4498-9094-bdf6193425c2",
    "project_id" : "060576798a80d5762fafc01a9b5eedc7",
    "description" : "",
    "vip_port_id" : "98697944-0cc7-4d3b-a829-001c2fb82232",
    "vip_address" : "192.168.0.214",
    "admin_state_up" : true,
    "provisioning_status" : "ACTIVE",
    "operating_status" : "ONLINE",
    "listeners" : [ ],
    "pools" : [ ],
    "tags" : [ {
      "key" : "tab_key",
      "value" : "tag1"
    } ],
    "provider" : "vlb",
    "created_at" : "2023-03-22T07:59:57Z",
    "updated_at" : "2023-03-22T07:59:59Z",
    "vpc_id" : "a1f33a4c-95b9-48a7-9350-684e2ed844b3",
    "enterprise_project_id" : "134f2181-5720-47e7-bd78-1356ed3737d6",
    "availability_zone_list" : [ ],
    "ipv6_vip_address" : null,
    "ipv6_vip_virsubnet_id" : null,
    "ipv6_vip_port_id" : null,
    "publicips" : [ {
      "publicip_id" : "3388574a-4f6f-4471-869e-97d74d21eee9",
      "publicip_address" : "88.88.87.205",
      "ip_version" : 4
    } ],
    "global_eips" : [ ],
    "elb_virsubnet_ids" : [ ],
    "elb_virsubnet_type" : null,
    "ip_target_enable" : false,
    "autoscaling" : {
      "enable" : false,
      "min_l7_flavor_id" : ""
    },
    "frozen_scene" : null,
    "public_border_group" : "center",
    "eips" : [ {
      "eip_id" : "3388574a-4f6f-4471-869e-97d74d21eee9",
      "eip_address" : "88.88.87.205",
      "ip_version" : 4
    } ],
    "guaranteed" : false,
    "billing_info" : null,
    "l4_flavor_id" : null,
    "l4_scale_flavor_id" : null,
    "l7_flavor_id" : null,
    "l7_scale_flavor_id" : null,
    "waf_failure_action" : "",
    "vip_subnet_cidr_id" : "abf31f3b-706e-4e55-a6dc-f2fcc707fd3a"
  },
  "request_id" : "bf29597181cb81b30d19f1a0115a157d"
}

SDK Sample Code

The SDK sample code is as follows.

  • Example 1: Creating a load balancer with a private IPv4 address

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateLoadBalancerSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateLoadBalancerRequest request = new CreateLoadBalancerRequest();
            CreateLoadBalancerRequestBody body = new CreateLoadBalancerRequestBody();
            List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>();
            listLoadbalancerAvailabilityZoneList.add("AZ1");
            CreateLoadBalancerOption loadbalancerbody = new CreateLoadBalancerOption();
            loadbalancerbody.withName("loadbalancer")
                .withDescription("simple lb")
                .withVipSubnetCidrId("1992ec06-f364-4ae3-b936-6a8cc24633b7")
                .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList)
                .withAdminStateUp(true);
            body.withLoadbalancer(loadbalancerbody);
            request.withBody(body);
            try {
                CreateLoadBalancerResponse response = client.createLoadBalancer(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Example 2: Creating a load balancer with an IPv4 EIP

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    package com.huaweicloud.sdk.test;
    
    import com.huaweicloud.sdk.core.auth.ICredential;
    import com.huaweicloud.sdk.core.auth.BasicCredentials;
    import com.huaweicloud.sdk.core.exception.ConnectionException;
    import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
    import com.huaweicloud.sdk.core.exception.ServiceResponseException;
    import com.huaweicloud.sdk.elb.v3.region.ElbRegion;
    import com.huaweicloud.sdk.elb.v3.*;
    import com.huaweicloud.sdk.elb.v3.model.*;
    
    import java.util.List;
    import java.util.ArrayList;
    
    public class CreateLoadBalancerSolution {
    
        public static void main(String[] args) {
            // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
            // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
            String ak = System.getenv("CLOUD_SDK_AK");
            String sk = System.getenv("CLOUD_SDK_SK");
            String projectId = "{project_id}";
    
            ICredential auth = new BasicCredentials()
                    .withProjectId(projectId)
                    .withAk(ak)
                    .withSk(sk);
    
            ElbClient client = ElbClient.newBuilder()
                    .withCredential(auth)
                    .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                    .build();
            CreateLoadBalancerRequest request = new CreateLoadBalancerRequest();
            CreateLoadBalancerRequestBody body = new CreateLoadBalancerRequestBody();
            CreateLoadBalancerBandwidthOption bandwidthPublicip = new CreateLoadBalancerBandwidthOption();
            bandwidthPublicip.withName("bandwidth_test")
                .withSize(2)
                .withChargeMode(CreateLoadBalancerBandwidthOption.ChargeModeEnum.fromValue("bandwidth"))
                .withShareType(CreateLoadBalancerBandwidthOption.ShareTypeEnum.fromValue("PER"));
            CreateLoadBalancerPublicIpOption publicipLoadbalancer = new CreateLoadBalancerPublicIpOption();
            publicipLoadbalancer.withNetworkType("5_bgp")
                .withBandwidth(bandwidthPublicip);
            List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>();
            listLoadbalancerAvailabilityZoneList.add("AZ1");
            CreateLoadBalancerOption loadbalancerbody = new CreateLoadBalancerOption();
            loadbalancerbody.withName("elb_eip-test")
                .withVipSubnetCidrId("e6e9271d-aef4-48f0-a93a-ccc7b09032c1")
                .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList)
                .withAdminStateUp(true)
                .withPublicip(publicipLoadbalancer);
            body.withLoadbalancer(loadbalancerbody);
            request.withBody(body);
            try {
                CreateLoadBalancerResponse response = client.createLoadBalancer(request);
                System.out.println(response.toString());
            } catch (ConnectionException e) {
                e.printStackTrace();
            } catch (RequestTimeoutException e) {
                e.printStackTrace();
            } catch (ServiceResponseException e) {
                e.printStackTrace();
                System.out.println(e.getHttpStatusCode());
                System.out.println(e.getRequestId());
                System.out.println(e.getErrorCode());
                System.out.println(e.getErrorMsg());
            }
        }
    }
    
  • Example 1: Creating a load balancer with a private IPv4 address

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateLoadBalancerRequest()
            listAvailabilityZoneListLoadbalancer = [
                "AZ1"
            ]
            loadbalancerbody = CreateLoadBalancerOption(
                name="loadbalancer",
                description="simple lb",
                vip_subnet_cidr_id="1992ec06-f364-4ae3-b936-6a8cc24633b7",
                availability_zone_list=listAvailabilityZoneListLoadbalancer,
                admin_state_up=True
            )
            request.body = CreateLoadBalancerRequestBody(
                loadbalancer=loadbalancerbody
            )
            response = client.create_load_balancer(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Example 2: Creating a load balancer with an IPv4 EIP

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    # coding: utf-8
    
    import os
    from huaweicloudsdkcore.auth.credentials import BasicCredentials
    from huaweicloudsdkelb.v3.region.elb_region import ElbRegion
    from huaweicloudsdkcore.exceptions import exceptions
    from huaweicloudsdkelb.v3 import *
    
    if __name__ == "__main__":
        # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak = os.environ["CLOUD_SDK_AK"]
        sk = os.environ["CLOUD_SDK_SK"]
        projectId = "{project_id}"
    
        credentials = BasicCredentials(ak, sk, projectId)
    
        client = ElbClient.new_builder() \
            .with_credentials(credentials) \
            .with_region(ElbRegion.value_of("<YOUR REGION>")) \
            .build()
    
        try:
            request = CreateLoadBalancerRequest()
            bandwidthPublicip = CreateLoadBalancerBandwidthOption(
                name="bandwidth_test",
                size=2,
                charge_mode="bandwidth",
                share_type="PER"
            )
            publicipLoadbalancer = CreateLoadBalancerPublicIpOption(
                network_type="5_bgp",
                bandwidth=bandwidthPublicip
            )
            listAvailabilityZoneListLoadbalancer = [
                "AZ1"
            ]
            loadbalancerbody = CreateLoadBalancerOption(
                name="elb_eip-test",
                vip_subnet_cidr_id="e6e9271d-aef4-48f0-a93a-ccc7b09032c1",
                availability_zone_list=listAvailabilityZoneListLoadbalancer,
                admin_state_up=True,
                publicip=publicipLoadbalancer
            )
            request.body = CreateLoadBalancerRequestBody(
                loadbalancer=loadbalancerbody
            )
            response = client.create_load_balancer(request)
            print(response)
        except exceptions.ClientRequestException as e:
            print(e.status_code)
            print(e.request_id)
            print(e.error_code)
            print(e.error_msg)
    
  • Example 1: Creating a load balancer with a private IPv4 address

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateLoadBalancerRequest{}
    	var listAvailabilityZoneListLoadbalancer = []string{
            "AZ1",
        }
    	nameLoadbalancer:= "loadbalancer"
    	descriptionLoadbalancer:= "simple lb"
    	vipSubnetCidrIdLoadbalancer:= "1992ec06-f364-4ae3-b936-6a8cc24633b7"
    	adminStateUpLoadbalancer:= true
    	loadbalancerbody := &model.CreateLoadBalancerOption{
    		Name: &nameLoadbalancer,
    		Description: &descriptionLoadbalancer,
    		VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer,
    		AvailabilityZoneList: listAvailabilityZoneListLoadbalancer,
    		AdminStateUp: &adminStateUpLoadbalancer,
    	}
    	request.Body = &model.CreateLoadBalancerRequestBody{
    		Loadbalancer: loadbalancerbody,
    	}
    	response, err := client.CreateLoadBalancer(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • Example 2: Creating a load balancer with an IPv4 EIP

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    package main
    
    import (
    	"fmt"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
        elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3"
    	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model"
        region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region"
    )
    
    func main() {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        ak := os.Getenv("CLOUD_SDK_AK")
        sk := os.Getenv("CLOUD_SDK_SK")
        projectId := "{project_id}"
    
        auth := basic.NewCredentialsBuilder().
            WithAk(ak).
            WithSk(sk).
            WithProjectId(projectId).
            Build()
    
        client := elb.NewElbClient(
            elb.ElbClientBuilder().
                WithRegion(region.ValueOf("<YOUR REGION>")).
                WithCredential(auth).
                Build())
    
        request := &model.CreateLoadBalancerRequest{}
    	nameBandwidth:= "bandwidth_test"
    	sizeBandwidth:= int32(2)
    	chargeModeBandwidth:= model.GetCreateLoadBalancerBandwidthOptionChargeModeEnum().BANDWIDTH
    	shareTypeBandwidth:= model.GetCreateLoadBalancerBandwidthOptionShareTypeEnum().PER
    	bandwidthPublicip := &model.CreateLoadBalancerBandwidthOption{
    		Name: &nameBandwidth,
    		Size: &sizeBandwidth,
    		ChargeMode: &chargeModeBandwidth,
    		ShareType: &shareTypeBandwidth,
    	}
    	publicipLoadbalancer := &model.CreateLoadBalancerPublicIpOption{
    		NetworkType: "5_bgp",
    		Bandwidth: bandwidthPublicip,
    	}
    	var listAvailabilityZoneListLoadbalancer = []string{
            "AZ1",
        }
    	nameLoadbalancer:= "elb_eip-test"
    	vipSubnetCidrIdLoadbalancer:= "e6e9271d-aef4-48f0-a93a-ccc7b09032c1"
    	adminStateUpLoadbalancer:= true
    	loadbalancerbody := &model.CreateLoadBalancerOption{
    		Name: &nameLoadbalancer,
    		VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer,
    		AvailabilityZoneList: listAvailabilityZoneListLoadbalancer,
    		AdminStateUp: &adminStateUpLoadbalancer,
    		Publicip: publicipLoadbalancer,
    	}
    	request.Body = &model.CreateLoadBalancerRequestBody{
    		Loadbalancer: loadbalancerbody,
    	}
    	response, err := client.CreateLoadBalancer(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

201

Successful request.

Error Codes

See Error Codes.