Skip to main content

Create

Creates a rule in the specified folder.

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);
}
})();

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 : string

    JQ 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 : PutQueueMessage

    Dead 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 : string

    JQ 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.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.