Skip to main content

AddListener

Adds a listener to the specified network load balancer.

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

const AddNetworkLoadBalancerListenerRequest =
cloudApi.loadbalancer.network_load_balancer_service
.AddNetworkLoadBalancerListenerRequest;
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;

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

const operation = await client.addListener(
AddNetworkLoadBalancerListenerRequest.fromPartial({
networkLoadBalancerId: "networkLoadBalancerId",
listenerSpec: {
name: "name",
// port: 0,
protocol: Listener_Protocol.TCP,
// externalAddressSpec: {
// address: "address",
// ipVersion: IpVersion.IPV4
// },
// internalAddressSpec: {
// address: "address",
// subnetId: "subnetId",
// ipVersion: IpVersion.IPV4
// },
// targetPort: 0
},
})
);
const finishedOp = await waitForOperation(operation, session);

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

AddNetworkLoadBalancerListenerRequest​

networkLoadBalancerId : string​

ID of the network load balancer to add a listener to. To get the network load balancer ID, use a NetworkLoadBalancerService.List request.

listenerSpec : ListenerSpec​

Listener spec.

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.

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.

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.