Create
Creates a rule in the specified folder.
- TypeScript
- Python
import {
cloudApi,
decodeMessage,
serviceClients,
Session,
waitForOperation,
} from "@yandex-cloud/nodejs-sdk";
const CreateRuleRequest =
cloudApi.serverless.eventrouter_rule_service.CreateRuleRequest;
const Rule = cloudApi.cdn.rule.Rule;
const Target_Status = cloudApi.serverless.eventrouter_rule.Target_Status;
(async () => {
const authToken = process.env["YC_OAUTH_TOKEN"];
const session = new Session({ oauthToken: authToken });
const client = session.client(serviceClients.RuleServiceClient);
const operation = await client.create(
CreateRuleRequest.fromPartial({
busId: "busId",
// name: "name",
// description: "description",
// labels: {"key": "labels"},
// filter: {
// jqFilter: "jqFilter"
// },
// targets: [{
// yds: {
// database: "database",
// streamName: "streamName",
// serviceAccountId: "serviceAccountId"
// },
// ymq: {
// queueArn: "queueArn",
// serviceAccountId: "serviceAccountId"
// },
// function: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// maxCount: 0,
// maxBytes: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// }
// },
// container: {
// containerId: "containerId",
// containerRevisionId: "containerRevisionId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// maxCount: 0,
// maxBytes: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// }
// },
// gatewayWsBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// maxCount: 0,
// maxBytes: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// }
// },
// logging: {
// logGroupId: "logGroupId",
// folderId: "folderId",
// serviceAccountId: "serviceAccountId"
// },
// workflow: {
// workflowId: "workflowId",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// maxCount: 0,
// maxBytes: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// }
// },
// transformer: {
// jqTransformer: "jqTransformer"
// },
// retrySettings: {
// retryAttempts: 0,
// maximumAge: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueArn: "queueArn",
// serviceAccountId: "serviceAccountId"
// },
// status: Target_Status.ENABLED
// }],
// deletionProtection: true
})
);
const finishedOp = await waitForOperation(operation, session);
if (finishedOp.response) {
const result = decodeMessage<typeof Rule>(finishedOp.response);
console.log(result);
}
})();
import os
import grpc
import yandexcloud
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import BatchSettings
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import ContainerTarget
from yandex.cloud.serverless.eventrouter.v1.rule_service_pb2 import CreateRuleMetadata
from yandex.cloud.serverless.eventrouter.v1.rule_service_pb2 import CreateRuleRequest
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import Filter
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import FunctionTarget
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import GatewayWebsocketBroadcastTarget
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import LoggingTarget
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import PutQueueMessage
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import RetrySettings
from yandex.cloud.cdn.v1.rule_pb2 import Rule
from yandex.cloud.serverless.eventrouter.v1.rule_service_pb2_grpc import RuleServiceStub
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import Target
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import Transformer
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import WorkflowTarget
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import YdsTarget
from yandex.cloud.serverless.eventrouter.v1.rule_pb2 import YmqTarget
token = os.getenv("YC_OAUTH_TOKEN")
sdk = yandexcloud.SDK(token=token)
service = sdk.client(RuleServiceStub)
operation = service.Create(
CreateRuleRequest(
bus_id="busId",
# name = "name",
# description = "description",
# labels = {"key": "labels"},
# filter = Filter(
# jq_filter = "jqFilter"
# ),
# targets = [Target(
# yds = YdsTarget(
# database = "database",
# stream_name = "streamName",
# service_account_id = "serviceAccountId"
# ),
# ymq = YmqTarget(
# queue_arn = "queueArn",
# service_account_id = "serviceAccountId"
# ),
# function = FunctionTarget(
# function_id = "functionId",
# function_tag = "functionTag",
# service_account_id = "serviceAccountId",
# batch_settings = BatchSettings(
# max_count = 0,
# max_bytes = 0,
# cutoff = Duration(
# seconds = 0,
# nanos = 0
# )
# )
# ),
# container = ContainerTarget(
# container_id = "containerId",
# container_revision_id = "containerRevisionId",
# path = "path",
# service_account_id = "serviceAccountId",
# batch_settings = BatchSettings(
# max_count = 0,
# max_bytes = 0,
# cutoff = Duration(
# seconds = 0,
# nanos = 0
# )
# )
# ),
# gateway_ws_broadcast = GatewayWebsocketBroadcastTarget(
# gateway_id = "gatewayId",
# path = "path",
# service_account_id = "serviceAccountId",
# batch_settings = BatchSettings(
# max_count = 0,
# max_bytes = 0,
# cutoff = Duration(
# seconds = 0,
# nanos = 0
# )
# )
# ),
# logging = LoggingTarget(
# log_group_id = "logGroupId",
# folder_id = "folderId",
# service_account_id = "serviceAccountId"
# ),
# workflow = WorkflowTarget(
# workflow_id = "workflowId",
# service_account_id = "serviceAccountId",
# batch_settings = BatchSettings(
# max_count = 0,
# max_bytes = 0,
# cutoff = Duration(
# seconds = 0,
# nanos = 0
# )
# )
# ),
# transformer = Transformer(
# jq_transformer = "jqTransformer"
# ),
# retry_settings = RetrySettings(
# retry_attempts = 0,
# maximum_age = Duration(
# seconds = 0,
# nanos = 0
# )
# ),
# dead_letter_queue = PutQueueMessage(
# queue_arn = "queueArn",
# service_account_id = "serviceAccountId"
# ),
# status = Target.Status.ENABLED
# )],
# deletion_protection = true
)
)
operation_result = sdk.wait_operation_and_get_result(
operation,
response_type=Rule,
meta_type=CreateRuleMetadata,
)
print(operation_result)
CreateRuleRequest
busId
: string
ID of the bus to create a rule for.
name
: string
Name of the rule.
description
: string
Description of the rule.
labels
: string
Labels for the rule.
filter
: Filter
Filter for the rule.
targets
: Target
Targets for the rule.
deletionProtection
: bool
Flag that disallow deletion of the rule.
Filter
One of condition
jqFilter
: stringJQ filter for matching events.
Target
Status
Status of the target.
STATUS_UNSPECIFIED
Status of the target.
ENABLED
Target is enabled.
DISABLED
Target is disabled.
RESOURCE_NOT_FOUND
Target does not exist.
PERMISSION_DENIED
Service account does not have read permission on source.
SUBJECT_NOT_FOUND
Service account not found.
One of target
yds
: YdsTarget
ymq
: YmqTarget
function
: FunctionTarget
container
: ContainerTarget
gatewayWsBroadcast
: GatewayWebsocketBroadcastTarget
logging
: LoggingTarget
workflow
: WorkflowTarget
transformer
: Transformer
Transformer of the target.
retrySettings
: RetrySettings
Retry settings of the target.
One of deadLetter
Dead letter settings of the target.
deadLetterQueue
: PutQueueMessageDead letter queue.
status
: Status
Status of the target.
YdsTarget
database
: string
Stream database.
streamName
: string
Full stream name, like /ru-central1/aoegtvhtp8ob****/cc8004q4lbo6****/test.
serviceAccountId
: string
Service account, which has write permission on the stream.
YmqTarget
queueArn
: string
Queue ARN. Example: yrn:yc:ymq:ru-central1:aoe***:test
serviceAccountId
: string
Service account which has write access to the queue.
FunctionTarget
functionId
: string
Function ID.
functionTag
: string
Function tag, optional.
serviceAccountId
: string
Service account which has call permission on the function, optional.
batchSettings
: BatchSettings
Batch settings.
ContainerTarget
containerId
: string
Container ID.
containerRevisionId
: string
Container revision ID.
path
: string
Endpoint HTTP path to invoke.
serviceAccountId
: string
Service account which should be used to call a container, optional.
batchSettings
: BatchSettings
Batch settings.
GatewayWebsocketBroadcastTarget
gatewayId
: string
Gateway ID.
path
: string
Path.
serviceAccountId
: string
Service account which has permission for writing to websockets.
batchSettings
: BatchSettings
Batch settings.
LoggingTarget
One of destination
Log group ID or folder ID.
logGroupId
: string
folderId
: string
serviceAccountId
: string
Service account which has permission for writing logs.
WorkflowTarget
workflowId
: string
Workflow ID.
serviceAccountId
: string
SA which should be used to start workflow.
batchSettings
: BatchSettings
Batch settings.
Transformer
One of transformer
jqTransformer
: stringJQ string inrerpolation expression for changing event format.
RetrySettings
retryAttempts
: int64
Maximum number of retries (extra calls) before an action fails.
maximumAge
: google.protobuf.Duration
Event goes to dlq when its age exceeds this value. Default is 24h.
PutQueueMessage
queueArn
: string
ID of the queue.
serviceAccountId
: string
Service account which has write permission on the queue.
BatchSettings
maxCount
: int64
Maximum batch size: trigger will send a batch if number of events exceeds this value.
maxBytes
: int64
Maximum batch size: trigger will send a batch if total size of events exceeds this value.
cutoff
: google.protobuf.Duration
Maximum batch size: trigger will send a batch if its lifetime exceeds this value.
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.