Skip to main content

Create

Creates a trigger in the specified folder.

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

const CreateTriggerRequest =
cloudApi.serverless.triggers_trigger_service.CreateTriggerRequest;
const LogLevel_Level = cloudApi.logging.log_entry.LogLevel_Level;
const Trigger = cloudApi.serverless.triggers_trigger.Trigger;
const Trigger_ContainerRegistryEventType =
cloudApi.serverless.triggers_trigger.Trigger_ContainerRegistryEventType;
const Trigger_ObjectStorageEventType =
cloudApi.serverless.triggers_trigger.Trigger_ObjectStorageEventType;

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

const operation = await client.create(
CreateTriggerRequest.fromPartial({
folderId: "folderId",
// name: "name",
// description: "description",
// labels: {"key": "labels"},
rule: {
// timer: {
// cronExpression: "cronExpression",
// payload: "payload",
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId"
// },
// invokeFunctionWithRetry: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainerWithRetry: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// messageQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// visibilityTimeout: {
// seconds: 0,
// nanos: 0
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId"
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// iotMessage: {
// registryId: "registryId",
// deviceId: "deviceId",
// mqttTopic: "mqttTopic",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// iotBrokerMessage: {
// brokerId: "brokerId",
// mqttTopic: "mqttTopic",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// objectStorage: {
// eventType: [Trigger_ObjectStorageEventType.OBJECT_STORAGE_EVENT_TYPE_CREATE_OBJECT],
// bucketId: "bucketId",
// prefix: "prefix",
// suffix: "suffix",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// containerRegistry: {
// eventType: [Trigger_ContainerRegistryEventType.CONTAINER_REGISTRY_EVENT_TYPE_CREATE_IMAGE],
// registryId: "registryId",
// imageName: "imageName",
// tag: "tag",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// cloudLogs: {
// logGroupId: ["logGroupId"],
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// }
// },
// logging: {
// logGroupId: "logGroupId",
// resourceType: ["resourceType"],
// resourceId: ["resourceId"],
// streamName: ["streamName"],
// levels: [LogLevel_Level.TRACE],
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// billingBudget: {
// billingAccountId: "billingAccountId",
// budgetId: "budgetId",
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// dataStream: {
// endpoint: "endpoint",
// database: "database",
// stream: "stream",
// serviceAccountId: "serviceAccountId",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// },
// mail: {
// email: "email",
// batchSettings: {
// size: 0,
// cutoff: {
// seconds: 0,
// nanos: 0
// }
// },
// attachmentsBucket: {
// bucketId: "bucketId",
// serviceAccountId: "serviceAccountId"
// },
// invokeFunction: {
// functionId: "functionId",
// functionTag: "functionTag",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// invokeContainer: {
// containerId: "containerId",
// path: "path",
// serviceAccountId: "serviceAccountId",
// retrySettings: {
// retryAttempts: 0,
// interval: {
// seconds: 0,
// nanos: 0
// }
// },
// deadLetterQueue: {
// queueId: "queueId",
// serviceAccountId: "serviceAccountId"
// }
// },
// gatewayWebsocketBroadcast: {
// gatewayId: "gatewayId",
// path: "path",
// serviceAccountId: "serviceAccountId"
// }
// }
},
})
);
const finishedOp = await waitForOperation(operation, session);

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

CreateTriggerRequest

folderId : string

ID of the folder to create a trigger in.

To get a folder ID make a yandex.cloud.resourcemanager.v1.FolderService.List request.

name : string

Name of the trigger. The name must be unique within the folder.

description : string

Description of the trigger.

labels : string

Resource labels as key:value pairs.

rule : Trigger.Rule

Trigger type.

Rule

Description of a rule for trigger activation.

One of rule

  • timer : Timer

    Rule for a timed trigger.

  • messageQueue : MessageQueue

    Rule for a message queue trigger.

  • iotMessage : IoTMessage

    Rule for a IoT Core trigger.

  • iotBrokerMessage : IoTBrokerMessage
  • objectStorage : ObjectStorage
  • containerRegistry : ContainerRegistry
  • cloudLogs : CloudLogs
  • logging : Logging
  • billingBudget : BillingBudget
  • dataStream : DataStream

Timer

Rule for activating a timed trigger.

cronExpression : string

Description of a schedule as a cron expression.

payload : string

Payload to be passed to function.

One of action

Action to be executed when the current time matches the cron_expression.

  • invokeFunction : InvokeFunctionOnce

    Instructions for invoking a function once.

  • invokeFunctionWithRetry : InvokeFunctionWithRetry

    Instructions for invoking a function with retry.

  • invokeContainerWithRetry : InvokeContainerWithRetry

    Instructions for invoking a container with retry.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

MessageQueue

Rule for activating a message queue trigger.

queueId : string

ID of the message queue in Message Queue.

serviceAccountId : string

ID of the service account which has read access to the message queue.

batchSettings : BatchSettings

Batch settings for processing messages in the queue.

visibilityTimeout : google.protobuf.Duration

Queue visibility timeout override.

  • invokeFunction : InvokeFunctionOnce

    Instructions for invoking a function once.

  • invokeContainer : InvokeContainerOnce

    Instructions for invoking a container once.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

IoTMessage

Rule for activating a IoT Core trigger.

registryId : string

ID of the IoT Core registry.

deviceId : string

ID of the IoT Core device in the registry.

mqttTopic : string

MQTT topic whose messages activate the trigger.

batchSettings : BatchSettings

Batch settings for processing events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

IoTBrokerMessage

Rule for activating a IoT Core Broker trigger.

brokerId : string

ID of the IoT Core broker.

mqttTopic : string

MQTT topic whose messages activate the trigger.

batchSettings : BatchSettings

Batch settings for processing events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

ObjectStorage

eventType : ObjectStorageEventType

Type (name) of events, at least one value is required.

bucketId : string

ID of the bucket.

prefix : string

Prefix of the object key. Filter, optional.

suffix : string

Suffix of the object key. Filter, optional.

batchSettings : BatchSettings

Batch settings for processing events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

ContainerRegistry

eventType : ContainerRegistryEventType

Type (name) of events, at least one value is required.

registryId : string

ID of the registry.

imageName : string

Docker-image name. Filter, optional.

tag : string

Docker-image tag. Filter, optional.

batchSettings : BatchSettings

Batch settings for processing events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

CloudLogs

logGroupId : string

Log group identifiers, at least one value is required.

batchSettings : CloudLogsBatchSettings

Batch settings for processing log events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

Logging

logGroupId : string

Log events filter settings.

resourceType : string
resourceId : string
streamName : string
levels : yandex.cloud.logging.v1.LogLevel.Level
batchSettings : LoggingBatchSettings

Batch settings for processing log events.

  • invokeFunction : InvokeFunctionWithRetry

    Instructions for invoking a function with retries as needed.

  • invokeContainer : InvokeContainerWithRetry

    Instructions for invoking a container with retries as needed.

  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

    Instructions for broadcasting to API gateway websocket once.

BillingBudget

billingAccountId : string
budgetId : string
  • invokeFunction : InvokeFunctionWithRetry
  • invokeContainer : InvokeContainerWithRetry
  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

DataStream

endpoint : string

Data stream endpoint.

database : string

Data stream database.

stream : string

Stream name.

serviceAccountId : string

ID of the service account which has permission to read data stream.

batchSettings : DataStreamBatchSettings

Batch settings for processing events.

  • invokeFunction : InvokeFunctionWithRetry
  • invokeContainer : InvokeContainerWithRetry
  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

Mail

email : string

Address to receive emails for trigger activation. Field is ignored for write requests and populated on trigger creation.

batchSettings : BatchSettings

Batch settings for processing events.

attachmentsBucket : ObjectStorageBucketSettings

Bucket settings for saving attachments.

  • invokeFunction : InvokeFunctionWithRetry
  • invokeContainer : InvokeContainerWithRetry
  • gatewayWebsocketBroadcast : GatewayWebsocketBroadcast

InvokeFunctionOnce

A single function invocation.

functionId : string

ID of the function to invoke.

functionTag : string

Version tag of the function to execute.

serviceAccountId : string

ID of the service account that should be used to invoke the function.

InvokeFunctionWithRetry

A function invocation with retries.

functionId : string

ID of the function to invoke.

functionTag : string

Version tag of the function to execute.

serviceAccountId : string

ID of the service account which has permission to invoke the function.

retrySettings : RetrySettings

Retry policy. If the field is not specified, or the value is empty, no retries will be attempted.

deadLetterQueue : PutQueueMessage

DLQ policy (no value means discarding a message).

InvokeContainerWithRetry

A container invocation with retries.

containerId : string

ID of the container to invoke.

path : string

Endpoint HTTP path to invoke.

serviceAccountId : string

ID of the service account which has permission to invoke the container.

retrySettings : RetrySettings

Retry policy. If the field is not specified, or the value is empty, no retries will be attempted.

deadLetterQueue : PutQueueMessage

DLQ policy (no value means discarding a message).

GatewayWebsocketBroadcast

gatewayId : string
path : string
serviceAccountId : string

sa which has permission for writing to websockets

BatchSettings

Settings for batch processing of messages in a queue.

size : int64

Batch size. Trigger will send the batch of messages to the function when the number of messages in the queue reaches size, or the cutoff time has passed.

cutoff : google.protobuf.Duration

Maximum wait time. Trigger will send the batch of messages to the function when the number of messages in the queue reaches size, or the cutoff time has passed.

InvokeContainerOnce

A single container invocation.

containerId : string

ID of the container to invoke.

path : string

Endpoint HTTP path to invoke.

serviceAccountId : string

ID of the service account which has permission to invoke the container.

CloudLogsBatchSettings

size : int64

Batch size. Trigger will send the batch of messages to the function when the number of messages in the log group reaches size, or the cutoff time has passed.

cutoff : google.protobuf.Duration

Maximum wait time. Trigger will send the batch of messages to the function when the number of messages in the log group reaches size, or the cutoff time has passed.

LoggingBatchSettings

size : int64

Batch size. Trigger will send the batch of messages to the associated function when the number of log events reaches this value, or the cutoff time has passed.

cutoff : google.protobuf.Duration

Maximum wait time. Trigger will send the batch of messages the time since the last batch exceeds the cutoff value, regardless of the amount of log events.

DataStreamBatchSettings

size : int64

Batch size in bytes. Trigger will send the batch of messages to the associated function when size of log events reaches this value, or the cutoff time has passed.

cutoff : google.protobuf.Duration

Maximum wait time. Trigger will send the batch of messages the time since the last batch exceeds the cutoff value, regardless of the amount of log events.

ObjectStorageBucketSettings

bucketId : string

Bucket for saving.

serviceAccountId : string

SA which has write permission on storage.

RetrySettings

Settings for retrying to invoke a function.

retryAttempts : int64

Maximum number of retries (extra invokes) before the action is considered failed.

interval : google.protobuf.Duration

Time in seconds to wait between individual retries.

PutQueueMessage

queueId : string

ID of the queue.

serviceAccountId : string

Service account which has write permission on the queue.

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.