Skip to main content

Create

Creates a network load balancer in the specified folder using the data specified in the request.

import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";

const CreateNetworkLoadBalancerRequest =
cloudApi.loadbalancer.network_load_balancer_service
.CreateNetworkLoadBalancerRequest;
const IpVersion = cloudApi.loadbalancer.network_load_balancer.IpVersion;
const Listener_Protocol =
cloudApi.loadbalancer.network_load_balancer.Listener_Protocol;
const NetworkLoadBalancer =
cloudApi.loadbalancer.network_load_balancer.NetworkLoadBalancer;
const NetworkLoadBalancer_Type =
cloudApi.loadbalancer.network_load_balancer.NetworkLoadBalancer_Type;

(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(
serviceClients.NetworkLoadBalancerServiceClient
);

const operation = await client.create(
CreateNetworkLoadBalancerRequest.fromPartial({
folderId: "folderId",
// name: "name",
// description: "description",
// labels: {"key": "labels"},
// regionId: "regionId",
type: NetworkLoadBalancer_Type.EXTERNAL,
// listenerSpecs: [{
// name: "name",
// port: 0,
// protocol: Listener_Protocol.TCP,
// externalAddressSpec: {
// address: "address",
// ipVersion: IpVersion.IPV4
// },
// internalAddressSpec: {
// address: "address",
// subnetId: "subnetId",
// ipVersion: IpVersion.IPV4
// },
// targetPort: 0
// }],
// attachedTargetGroups: [{
// targetGroupId: "targetGroupId",
// healthChecks: [{
// name: "name",
// interval: {
// seconds: 0,
// nanos: 0
// },
// timeout: {
// seconds: 0,
// nanos: 0
// },
// unhealthyThreshold: 0,
// healthyThreshold: 0,
// tcpOptions: {
// port: 0
// },
// httpOptions: {
// port: 0,
// path: "path"
// }
// }]
// }],
// deletionProtection: true
})
);
const finishedOp = await waitForOperation(operation, session);

if (finishedOp.response) {
const result = decodeMessage<typeof NetworkLoadBalancer>(
finishedOp.response
);
console.log(result);
}
})();

CreateNetworkLoadBalancerRequest

folderId : string

ID of the folder to create a network load balancer in. To get the folder ID, use a NetworkLoadBalancerService.List request.

name : string

Name of the network load balancer. The name must be unique within the folder.

description : string

Description of the network load balancer.

labels : string

Resource labels as key:value pairs.

regionId : string

ID of the region where the network load balancer resides.

type : NetworkLoadBalancer.Type

Type of the network load balancer.

listenerSpecs : ListenerSpec

List of listeners and their specs for the network load balancer.

attachedTargetGroups : AttachedTargetGroup

List of attached target groups for the network load balancer.

deletionProtection : bool

Specifies if network load balancer protected from deletion.

ListenerSpec

Listener specification that will be used by a network load balancer.

name : string

Name of the listener. The name must be unique for each listener on a single load balancer. 3-63 characters long.

port : int64

Port for incoming traffic.

protocol : Listener.Protocol

Protocol for incoming traffic.

One of address

IP address for incoming traffic. Either the ID of the previously created address or the address specification.

  • externalAddressSpec : ExternalAddressSpec

    External IP address specification.

  • internalAddressSpec : InternalAddressSpec

    Internal IP address specification.

targetPort : int64

Port of a target. Acceptable values are 1 to 65535, inclusive.

AttachedTargetGroup

An AttachedTargetGroup resource. For more information, see Targets and groups.

targetGroupId : string

ID of the target group.

healthChecks : HealthCheck

A health check to perform on the target group. For now we accept only one health check per AttachedTargetGroup.

ExternalAddressSpec

External address specification that is used by ListenerSpec.

address : string

Public IP address for a listener. If you provide a static public IP address for the NetworkLoadBalancerService.Update method, it will replace the existing listener address.

ipVersion : IpVersion

IP version.

InternalAddressSpec

Internal address specification that is used by ListenerSpec.

address : string

Internal IP address for a listener.

subnetId : string

ID of the subnet.

ipVersion : IpVersion

IP version.

HealthCheck

A HealthCheck resource. For more information, see Health check.

TcpOptions

Configuration option for a TCP health check.

port : int64

Port to use for TCP health checks.

HttpOptions

Configuration option for an HTTP health check.

port : int64

Port to use for HTTP health checks.

path : string

URL path to set for health checking requests for every target in the target group. For example /ping. The default path is /.

name : string

Name of the health check. The name must be unique for each target group that attached to a single load balancer. 3-63 characters long.

interval : google.protobuf.Duration

The interval between health checks. The default is 2 seconds.

timeout : google.protobuf.Duration

Timeout for a target to return a response for the health check. The default is 1 second.

unhealthyThreshold : int64

Number of failed health checks before changing the status to UNHEALTHY. The default is 2.

healthyThreshold : int64

Number of successful health checks required in order to set the HEALTHY status for the target. The default is 2.

One of options

Protocol to use for the health check. Either TCP or HTTP.

  • tcpOptions : TcpOptions

    Options for TCP health check.

  • httpOptions : HttpOptions

    Options for HTTP health check.

TcpOptions

Configuration option for a TCP health check.

port : int64

Port to use for TCP health checks.

HttpOptions

Configuration option for an HTTP health check.

port : int64

Port to use for HTTP health checks.

path : string

URL path to set for health checking requests for every target in the target group. For example /ping. The default path is /.

Operation

An Operation resource. For more information, see Operation.

id : string

ID of the operation.

description : string

Description of the operation. 0-256 characters long.

createdAt : google.protobuf.Timestamp

Creation timestamp.

createdBy : string

ID of the user or service account who initiated the operation.

modifiedAt : google.protobuf.Timestamp

The time when the Operation resource was last modified.

done : bool

If the value is false, it means the operation is still in progress. If true, the operation is completed, and either error or response is available.

metadata : google.protobuf.Any

Service-specific metadata associated with the operation. It typically contains the ID of the target resource that the operation is performed on. Any method that returns a long-running operation should document the metadata type, if any.

One of result

The operation result. If done == false and there was no failure detected, neither error nor response is set. If done == false and there was a failure detected, error is set. If done == true, exactly one of error or response is set.

  • error : google.rpc.Status

    The error result of the operation in case of failure or cancellation.

  • response : google.protobuf.Any
    The normal response of the operation in case of success.

    If the original method returns no data on success, such as Delete, the response is google.protobuf.Empty. If the original method is the standard Create/Update, the response should be the target resource of the operation. Any method that returns a long-running operation should document the response type, if any.