UpdateBackend
Updates the specified backend.
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
const BackendGroup = cloudApi.apploadbalancer.backend_group.BackendGroup;
const LoadBalancingMode =
cloudApi.apploadbalancer.backend_group.LoadBalancingMode;
const UpdateBackendRequest =
cloudApi.apploadbalancer.backend_group_service.UpdateBackendRequest;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.BackendGroupServiceClient);
const operation = await client.updateBackend(
UpdateBackendRequest.fromPartial({
backendGroupId: "backendGroupId",
// updateMask: {
// paths: ["paths"]
// },
// http: {
// name: "name",
// backendWeight: {
// value: 0
// },
// loadBalancingConfig: {
// panicThreshold: 0,
// localityAwareRoutingPercent: 0,
// strictLocality: true,
// mode: LoadBalancingMode.RANDOM
// },
// port: 0,
// targetGroups: {
// targetGroupIds: ["targetGroupIds"]
// },
// storageBucket: {
// bucket: "bucket"
// },
// healthchecks: [{
// timeout: {
// seconds: 0,
// nanos: 0
// },
// interval: {
// seconds: 0,
// nanos: 0
// },
// intervalJitterPercent: 0,
// healthyThreshold: 0,
// unhealthyThreshold: 0,
// healthcheckPort: 0,
// stream: {
// send: {
// text: "text"
// },
// receive: {
// text: "text"
// }
// },
// http: {
// host: "host",
// path: "path",
// useHttp2: true
// },
// grpc: {
// serviceName: "serviceName"
// },
// plaintext: {
// },
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// }
// }],
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// },
// useHttp2: true
// },
// grpc: {
// name: "name",
// backendWeight: {
// value: 0
// },
// loadBalancingConfig: {
// panicThreshold: 0,
// localityAwareRoutingPercent: 0,
// strictLocality: true,
// mode: LoadBalancingMode.RANDOM
// },
// port: 0,
// targetGroups: {
// targetGroupIds: ["targetGroupIds"]
// },
// healthchecks: [{
// timeout: {
// seconds: 0,
// nanos: 0
// },
// interval: {
// seconds: 0,
// nanos: 0
// },
// intervalJitterPercent: 0,
// healthyThreshold: 0,
// unhealthyThreshold: 0,
// healthcheckPort: 0,
// stream: {
// send: {
// text: "text"
// },
// receive: {
// text: "text"
// }
// },
// http: {
// host: "host",
// path: "path",
// useHttp2: true
// },
// grpc: {
// serviceName: "serviceName"
// },
// plaintext: {
// },
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// }
// }],
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// }
// },
// stream: {
// name: "name",
// backendWeight: {
// value: 0
// },
// loadBalancingConfig: {
// panicThreshold: 0,
// localityAwareRoutingPercent: 0,
// strictLocality: true,
// mode: LoadBalancingMode.RANDOM
// },
// port: 0,
// targetGroups: {
// targetGroupIds: ["targetGroupIds"]
// },
// healthchecks: [{
// timeout: {
// seconds: 0,
// nanos: 0
// },
// interval: {
// seconds: 0,
// nanos: 0
// },
// intervalJitterPercent: 0,
// healthyThreshold: 0,
// unhealthyThreshold: 0,
// healthcheckPort: 0,
// stream: {
// send: {
// text: "text"
// },
// receive: {
// text: "text"
// }
// },
// http: {
// host: "host",
// path: "path",
// useHttp2: true
// },
// grpc: {
// serviceName: "serviceName"
// },
// plaintext: {
// },
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// }
// }],
// tls: {
// sni: "sni",
// validationContext: {
// trustedCaId: "trustedCaId",
// trustedCaBytes: "trustedCaBytes"
// }
// },
// enableProxyProtocol: true
// }
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof BackendGroup>(finishedOp.response);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import BackendGroup
from yandex.cloud.apploadbalancer.v1.backend_group_service_pb2_grpc import BackendGroupServiceStub
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import BackendTls
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import GrpcBackend
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import HealthCheck
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import HttpBackend
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import LoadBalancingConfig
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import LoadBalancingMode
from yandex.cloud.apploadbalancer.v1.payload_pb2 import Payload
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import PlaintextTransportSettings
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import SecureTransportSettings
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import StorageBucketBackend
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import StreamBackend
from yandex.cloud.apploadbalancer.v1.backend_group_pb2 import TargetGroupsBackend
from yandex.cloud.apploadbalancer.v1.backend_group_service_pb2 import UpdateBackendMetadata
from yandex.cloud.apploadbalancer.v1.backend_group_service_pb2 import UpdateBackendRequest
from yandex.cloud.apploadbalancer.v1.tls_pb2 import ValidationContext
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(BackendGroupServiceStub)
operation = service.UpdateBackend(
UpdateBackendRequest(
backend_group_id="backendGroupId",
# update_mask = FieldMask.FromJsonString("field1,field2"),
# http = HttpBackend(
# name = "name",
# backend_weight = Int64Value(
# value = 0
# ),
# load_balancing_config = LoadBalancingConfig(
# panic_threshold = 0,
# locality_aware_routing_percent = 0,
# strict_locality = true,
# mode = LoadBalancingMode.RANDOM
# ),
# port = 0,
# target_groups = TargetGroupsBackend(
# target_group_ids = ["targetGroupIds"]
# ),
# storage_bucket = StorageBucketBackend(
# bucket = "bucket"
# ),
# healthchecks = [HealthCheck(
# timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval_jitter_percent = 0,
# healthy_threshold = 0,
# unhealthy_threshold = 0,
# healthcheck_port = 0,
# stream = HealthCheck.StreamHealthCheck(
# send = Payload(
# text = "text"
# ),
# receive = Payload(
# text = "text"
# )
# ),
# http = HealthCheck.HttpHealthCheck(
# host = "host",
# path = "path",
# use_http_2 = true
# ),
# grpc = HealthCheck.GrpcHealthCheck(
# service_name = "serviceName"
# ),
# plaintext = PlaintextTransportSettings(
# ),
# tls = SecureTransportSettings(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# )
# )],
# tls = BackendTls(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# ),
# use_http_2 = true
# ),
# grpc = GrpcBackend(
# name = "name",
# backend_weight = Int64Value(
# value = 0
# ),
# load_balancing_config = LoadBalancingConfig(
# panic_threshold = 0,
# locality_aware_routing_percent = 0,
# strict_locality = true,
# mode = LoadBalancingMode.RANDOM
# ),
# port = 0,
# target_groups = TargetGroupsBackend(
# target_group_ids = ["targetGroupIds"]
# ),
# healthchecks = [HealthCheck(
# timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval_jitter_percent = 0,
# healthy_threshold = 0,
# unhealthy_threshold = 0,
# healthcheck_port = 0,
# stream = HealthCheck.StreamHealthCheck(
# send = Payload(
# text = "text"
# ),
# receive = Payload(
# text = "text"
# )
# ),
# http = HealthCheck.HttpHealthCheck(
# host = "host",
# path = "path",
# use_http_2 = true
# ),
# grpc = HealthCheck.GrpcHealthCheck(
# service_name = "serviceName"
# ),
# plaintext = PlaintextTransportSettings(
# ),
# tls = SecureTransportSettings(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# )
# )],
# tls = BackendTls(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# )
# ),
# stream = StreamBackend(
# name = "name",
# backend_weight = Int64Value(
# value = 0
# ),
# load_balancing_config = LoadBalancingConfig(
# panic_threshold = 0,
# locality_aware_routing_percent = 0,
# strict_locality = true,
# mode = LoadBalancingMode.RANDOM
# ),
# port = 0,
# target_groups = TargetGroupsBackend(
# target_group_ids = ["targetGroupIds"]
# ),
# healthchecks = [HealthCheck(
# timeout = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval = Duration(
# seconds = 0,
# nanos = 0
# ),
# interval_jitter_percent = 0,
# healthy_threshold = 0,
# unhealthy_threshold = 0,
# healthcheck_port = 0,
# stream = HealthCheck.StreamHealthCheck(
# send = Payload(
# text = "text"
# ),
# receive = Payload(
# text = "text"
# )
# ),
# http = HealthCheck.HttpHealthCheck(
# host = "host",
# path = "path",
# use_http_2 = true
# ),
# grpc = HealthCheck.GrpcHealthCheck(
# service_name = "serviceName"
# ),
# plaintext = PlaintextTransportSettings(
# ),
# tls = SecureTransportSettings(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# )
# )],
# tls = BackendTls(
# sni = "sni",
# validation_context = ValidationContext(
# trusted_ca_id = "trustedCaId",
# trusted_ca_bytes = "trustedCaBytes"
# )
# ),
# enable_proxy_protocol = true
# )
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=BackendGroup,
meta_type=UpdateBackendMetadata,
)
print(operation_result)
UpdateBackendRequest
backendGroupId
: string
ID of the backend group to update the backend in.
updateMask
: google.protobuf.FieldMask
Field mask that specifies which attributes of the backend should be updated.
One of backend
Name of the backend to update (required) and new settings for the backend.
http
: HttpBackendNew settings for the HTTP backend.
grpc
: GrpcBackendNew settings for the gRPC backend.
stream
: StreamBackendNew settings for the stream (TCP) backend.
HttpBackend
An HTTP backend resource.
name
: string
Name of the backend.
backendWeight
: google.protobuf.Int64Value
Backend weight. Traffic is distributed between backends of a backend group according to their weights.
Weights must be set either for all backends in a group or for none of them. Setting no weights is the same as setting equal non-zero weights for all backends.
If the weight is non-positive, traffic is not sent to the backend.
loadBalancingConfig
: LoadBalancingConfig
Load balancing configuration for the backend.
port
: int64
Port used by all targets to receive traffic.
One of backendType
Reference to targets that belong to the backend.
A backend may be a set of target groups or an Object Storage bucket. For details about backend types, see documentation.
targetGroups
: TargetGroupsBackendTarget groups that belong to the backend. For details about target groups, see
storageBucket
: StorageBucketBackendObject Storage bucket to use as the backend. For details about buckets, see
If a bucket is used as a backend, the list of bucket objects and the objects themselves must be publicly accessible. For instructions, see documentation.
healthchecks
: HealthCheck
Health checks to perform on targets from target groups. For details about health checking, see documentation.
If no health checks are specified, active health checking is not performed.
tls
: BackendTls
Settings for TLS connections between load balancer nodes and backend targets.
If specified, the load balancer establishes HTTPS (HTTP over TLS) connections with targets and compares received certificates with the one specified in BackendTls.validation_context. If not specified, the load balancer establishes unencrypted HTTP connections with targets.
useHttp2
: bool
Enables HTTP/2 usage in connections between load balancer nodes and backend targets.
Default value: false
, HTTP/1.1 is used.
GrpcBackend
A gRPC backend resource.
name
: string
Name of the backend.
backendWeight
: google.protobuf.Int64Value
Backend weight. Traffic is distributed between backends of a backend group according to their weights.
Weights must be set either for all backends of a group or for none of them. Setting no weights is the same as setting equal non-zero weights for all backends.
If the weight is non-positive, traffic is not sent to the backend.
loadBalancingConfig
: LoadBalancingConfig
Load balancing configuration for the backend.
port
: int64
Port used by all targets to receive traffic.
targetGroups
: TargetGroupsBackendTarget groups that belong to the backend.
healthchecks
: HealthCheck
Health checks to perform on targets from target groups. For details about health checking, see documentation.
If no health checks are specified, active health checking is not performed.
tls
: BackendTls
Settings for TLS connections between load balancer nodes and backend targets.
If specified, the load balancer establishes HTTPS (HTTP over TLS) connections with targets and compares received certificates with the one specified in BackendTls.validation_context. If not specified, the load balancer establishes unencrypted HTTP connections with targets.
StreamBackend
A stream (TCP) backend resource.
name
: string
Name of the backend.
backendWeight
: google.protobuf.Int64Value
Backend weight. Traffic is distributed between backends of a backend group according to their weights.
Weights must be set either for all backends in a group or for none of them. Setting no weights is the same as setting equal non-zero weights for all backends.
If the weight is non-positive, traffic is not sent to the backend.
loadBalancingConfig
: LoadBalancingConfig
Load balancing configuration for the backend.
port
: int64
Port used by all targets to receive traffic.
targetGroups
: TargetGroupsBackendTarget groups that belong to the backend. For details about target groups, see
healthchecks
: HealthCheck
Health checks to perform on targets from target groups. For details about health checking, see documentation.
If no health checks are specified, active health checking is not performed.
tls
: BackendTls
Settings for TLS connections between load balancer nodes and backend targets.
If specified, the load balancer establishes TLS-encrypted TCP connections with targets and compares received certificates with the one specified in BackendTls.validation_context. If not specified, the load balancer establishes unencrypted TCP connections with targets.
enableProxyProtocol
: bool
If set, proxy protocol will be enabled for this backend.
LoadBalancingConfig
A load balancing configuration resource.
panicThreshold
: int64
Threshold for panic mode.
If percentage of healthy backends in the group drops below threshold, panic mode will be activated and traffic will be routed to all backends, regardless of their health check status. This helps to avoid overloading healthy backends. For details about panic mode, see documentation.
If the value is 0
, panic mode will never be activated and traffic is routed only to healthy backends at all times.
Default value: 0
.
localityAwareRoutingPercent
: int64
Percentage of traffic that a load balancer node sends to healthy backends in its availability zone. The rest is divided equally between other zones. For details about zone-aware routing, see documentation.
If there are no healthy backends in an availability zone, all the traffic is divided between other zones.
If strict_locality is true
, the specified value is ignored.
A load balancer node sends all the traffic within its availability zone, regardless of backends' health.
Default value: 0
.
strictLocality
: bool
Specifies whether a load balancer node should only send traffic to backends in its availability zone, regardless of their health, and ignore backends in other zones.
If set to true
and there are no healthy backends in the zone, the node in this zone will respond
to incoming traffic with errors.
For details about strict locality, see documentation.
If strict_locality
is true
, the value specified in locality_aware_routing_percent is ignored.
Default value: false
.
mode
: LoadBalancingMode
Load balancing mode for the backend.
For details about load balancing modes, see documentation.
TargetGroupsBackend
A resource for target groups that belong to the backend.
targetGroupIds
: string
List of ID's of target groups that belong to the backend.
To get the ID's of all available target groups, make a TargetGroupService.List request.
StorageBucketBackend
A resource for Object Storage bucket used as a backend. For details about the concept, see documentation.
bucket
: string
Name of the bucket.
HealthCheck
A health check resource. For details about the concept, see documentation.
StreamHealthCheck
A resource for TCP stream health check settings.
send
: Payload
Message sent to targets during TCP data transfer.
If not specified, no data is sent to the target.
receive
: Payload
Data that must be contained in the messages received from targets for a successful health check.
If not specified, no messages are expected from targets, and those that are received are not checked.
HttpHealthCheck
A resource for HTTP health check settings.
host
: string
Value for the HTTP/1.1 Host
header or the HTTP/2 :authority
pseudo-header used in requests to targets.
path
: string
HTTP path used in requests to targets: request URI for HTTP/1.1 request line
or value for the HTTP/2 :path
pseudo-header.
useHttp2
: bool
Enables HTTP/2 usage in health checks.
Default value: false
, HTTP/1.1 is used.
GrpcHealthCheck
A resource for gRPC health check settings.
serviceName
: string
Name of the gRPC service to be checked.
If not specified, overall health is checked.
For details about the concept, see GRPC Health Checking Protocol.
timeout
: google.protobuf.Duration
Health check timeout.
The timeout is the time allowed for the target to respond to a check. If the target doesn't respond in time, the check is considered failed.
interval
: google.protobuf.Duration
Base interval between consecutive health checks.
intervalJitterPercent
: double
healthyThreshold
: int64
Number of consecutive successful health checks required to mark an unhealthy target as healthy.
Both 0
and 1
values amount to one successful check required.
The value is ignored when a load balancer is initialized; a target is marked healthy after one successful check.
Default value: 0
.
unhealthyThreshold
: int64
Number of consecutive failed health checks required to mark a healthy target as unhealthy.
Both 0
and 1
values amount to one unsuccessful check required.
The value is ignored if a health check is failed due to an HTTP 503 Service Unavailable
response from the target
(not applicable to TCP stream health checks). The target is immediately marked unhealthy.
Default value: 0
.
healthcheckPort
: int64
Port used for health checks.
If not specified, the backend port (HttpBackend.port or GrpcBackend.port) is used for health checks.
One of healthcheck
Protocol-specific health check settings.
The protocols of the backend and of its health check may differ, e.g. a gRPC health check may be specified for an HTTP backend.
stream
: StreamHealthCheckTCP stream health check settings.
http
: HttpHealthCheckHTTP health check settings.
grpc
: GrpcHealthCheckgRPC health check settings.
One of transportSettings
Optional transport protocol for health checks. When not set, health checks use the same protocol as the proxied traffic. Use this when health checks' protocol settings differ from their backend, e.g. plaintext health checks for a TLS backend.
plaintext
: PlaintextTransportSettings
tls
: SecureTransportSettings
BackendTls
A resource for backend TLS settings.
sni
: string
Server Name Indication (SNI) string for TLS connections.
validationContext
: ValidationContext
Validation context for TLS connections.
Payload
A health check payload resource.
One of payload
Payload.
text
: stringPayload text.
StreamHealthCheck
A resource for TCP stream health check settings.
send
: Payload
Message sent to targets during TCP data transfer.
If not specified, no data is sent to the target.
receive
: Payload
Data that must be contained in the messages received from targets for a successful health check.
If not specified, no messages are expected from targets, and those that are received are not checked.
HttpHealthCheck
A resource for HTTP health check settings.
host
: string
Value for the HTTP/1.1 Host
header or the HTTP/2 :authority
pseudo-header used in requests to targets.
path
: string
HTTP path used in requests to targets: request URI for HTTP/1.1 request line
or value for the HTTP/2 :path
pseudo-header.
useHttp2
: bool
Enables HTTP/2 usage in health checks.
Default value: false
, HTTP/1.1 is used.
GrpcHealthCheck
A resource for gRPC health check settings.
serviceName
: string
Name of the gRPC service to be checked.
If not specified, overall health is checked.
For details about the concept, see GRPC Health Checking Protocol.
PlaintextTransportSettings
Transport settings to be used instead of the settings configured per-cluster
SecureTransportSettings
Transport settings to be used instead of the settings configured per-cluster
sni
: string
SNI string for TLS connections.
validationContext
: ValidationContext
Validation context for backend TLS connections.
ValidationContext
A TLS validation context resource.
One of trustedCa
TLS certificate issued by a trusted certificate authority (CA).
trustedCaId
: string
trustedCaBytes
: stringX.509 certificate contents in PEM format.
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.StatusThe error result of the operation in case of failure or cancellation.
response
: google.protobuf.AnyThe 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.