Creating a trigger for Yandex Cloud Logs
To create a trigger, you need:
- Functions that the trigger will call. If you don't have a function:
- The Dead Letter Queue where messages that the function couldn't process are moved. If you don't have a queue, create one.
- A service account with rights for function call. If you don't have a service account, create one.
Creating a trigger
The trigger is initiated within 5 minutes of being created.
- In the management console, go to the folder where you want to create a trigger.
- Open Cloud Functions.
- Go to the Triggers tab.
- Click Create trigger.
- Under Basic parameters:
- Enter a name and description for the trigger.
- In the Type field, select Cloud Logs.
- Under Cloud Logs settings, specify what sources the function will process messages from. Log groups are identified automatically.
- Under Batch message settings, specify the message batch size and the maximum waiting time. The trigger will send the batch of messages to the function when the number of messages in the log group reaches the specified batch size or the maximum waiting time expires.
- Under Function settings:
Select the function for the trigger to call.
Selecting a function that serves as the source of logs for the trigger may result in an exponential rise in calls.
Specify the function version tag.
Specify the service account to be used to call the function.
- Under Repeat request settings:
- In the Interval field, specify the time after which the function will be invoked again if the current attempt fails. Acceptable values are from 10 to 60 seconds.
- In the Number of attempts field, specify the number of invocation retries before the trigger moves a message to the Dead Letter Queue. Acceptable values are from 1 to 5.
- Under Dead Letter Queue settings, select the Dead Letter Queue and service account with rights to write messages to it.
- Click Create trigger.
If you don't have the Yandex.Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the
To create a trigger, run the command:
yc serverless trigger create cloud-logs \ --name <trigger name> \ --log-groups <comma-separated list of log group IDs> \ --batch-size 10 \ --batch-cutoff 10s \ --invoke-function-id <function ID> \ --invoke-function-service-account-id <service account ID> \ --retry-attempts 1 \ --retry-interval 10s \ --dlq-queue-id <Dead Letter Queue ID> \ --dlq-service-account-id <service account ID>
--name: Trigger name.
--log-groups: List of IDs of log groups.
--batch-size: Message batch size. Values can be from 1 to 10. The default is 1.
--batch-cutoff: Maximum waiting time. Values can be from 0 to 20 seconds. The default is 10 seconds. The trigger will send the batch of messages to the function when the number of messages in the log group reaches the
--invoke-function-id: Function ID.
--invoke-function-service-account-id: Service account with rights to call the function.
--retry-attempts: The time after which the function will be invoked again if the current attempt fails. Values can be from 10 to 60 seconds. The default is 10 seconds.
--retry-interval: The number of invocation retries before the trigger moves a message to the Dead Letter Queue. Values can be from 1 to 5. The default is 1.
--dlq-queue-id: ID of the Dead Letter Queue.
--dlq-service-account-id: Service account with rights to write messages to the Dead Letter Queue.
id: a1s92agr8mpgeo3kjt48 folder_id: b1g88tflru0ek1omtsu0 created_at: "2020-08-13T10:46:55.947Z" name: log-trigger rule: cloud_logs: log_group_id: - eolhui6rdfg564kl8h67 - eol7tkttsd345gju74df batch_settings: size: "1" cutoff: 10s invoke_function: function_id: d4eofc7n0m03lmudsk7y function_tag: $latest service_account_id: aje3932acd0c5ur7drte retry_settings: retry_attempts: "1" interval: 10s dead_letter_queue: queue-id: yrn:yc:ymq:ru-central1:aoek49ghmknnpj1ll45e:dlq service-account-id: aje3932acd0c5ur7dagp status: ACTIVE
You can create a trigger for Cloud Logs using the create API method.
Checking the result
Make sure the trigger is working properly. To do this, view the logs of:
- The function that the trigger runs.
- The functions that are specified as log sources.
View the logs of the registries and devices that are specified as log sources.