Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Serverless Containers
  • Comparison with other Yandex Cloud services
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Getting an IAM token for a service account using a container
    • Getting information about a container
    • Managing rights to access a container
    • Creating a container
    • Invoking a container
    • Managing a container
    • Getting information about a trigger
    • Creating a trigger
      • Create a timer
      • Creating a trigger for Message Queue
      • Creating a trigger for Object Storage
      • Creating a trigger for Container Registry
      • Creating a trigger for Cloud Logging
      • Creating a trigger for Yandex IoT Core
      • Creating a trigger for budgets
      • Creating a trigger for Data Streams
      • Creating an email trigger
    • Managing triggers
  • Concepts
  • Practical guidelines
  • Access management
  • Pricing policy
  • Containers API reference
  • API Triggers reference
  • Questions and answers
  1. Step-by-step instructions
  2. Creating a trigger
  3. Creating a trigger for Cloud Logging

Creating a trigger for Cloud Logging that invokes a Serverless Containers container

Written by
Yandex Cloud
  • Before you begin
  • Creating a trigger
  • Checking the result
  • See also

Create a trigger for Cloud Logging that invokes a Serverless Containers container when entries are added to a log group.

Before you begin

To create a trigger, you need:

  • A container that the trigger will invoke. If you don't have a container:

    • Create a container.
    • Create a container revision.
  • (optional) A Dead Letter Queue where messages that could not be processed by a container will be redirected. If you don't have a queue, create one.

  • Service account with rights to invoke the container and (optionally) write messages to the Dead Letter Queue. You can use the same service account or different ones. If you don't have a service account, create one.

  • The log group that activates the trigger when records are added to it. If you don't have a log group, create one.

Creating a trigger

Note

The trigger is initiated within 5 minutes of being created.

Management console
CLI
API
  1. In the management console, select the folder where you wish to create your trigger.

  2. Open Serverless Containers.

  3. On the left-hand panel, select Triggers.

  4. Click Create trigger.

  5. Under Basic parameters:

    • Enter a name and description for the trigger.
    • In the Type field, select Cloud Logging.
    • In the Launched resource field, select Container.
  6. Under Cloud Logging settings, specify:

    • The log group.
    • (Optional) Resource types: Yandex Cloud or your services, such as, serverless.function.
    • (Optional) IDs of Yandex Cloud or your resources, such as Serverless Containers containers.
    • (Optional) Logging levels.

    A trigger activates when records that match all the optional settings are added to the specified log group. If an optional setting is undefined, the trigger activates for any value of the setting.

  7. (optional) Under Batch message settings, specify:

    • Batch size. Valid values range from 1 to 100. The default is 1.
    • Maximum wait time. Valid values range from 1 to 60 seconds. The default is 1 second.

    The trigger groups messages for a period of time not exceeding the specified timeout and sends them to a container. However, the number of messages does not exceed the specified group size.

  8. Under Container settings, select a container and specify:

    • A container revision.
    • A service account to be used to invoke the container.
  9. (optional) Under Repeat request settings:

    • In the Interval field, specify the time delay for the container to be invoked again if the current attempt fails. Values can be from 10 to 60 seconds. The default is 10 seconds.
    • In the Number of attempts field, specify 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.
  10. (optional) Under Dead Letter Queue settings, select the Dead Letter Queue and the service account with write privileges for this queue.

  11. 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 --folder-name or --folder-id parameter.

To create a trigger that invokes a container, run the command:

yc serverless trigger create logging \
  --name <trigger_name> \
  --log-group-name <log_group_name> \
  --batch-size 1 \
  --batch-cutoff 1s \
  --invoke-container-id <container_ID> \
  --invoke-container-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>

Where:

  • --name: Trigger name.
  • --log-group-name: Name of the log group that invokes a container when records are added.
  • --batch-size: Message batch size. Optional. Valid values range from 1 to 100. The default is 1.
  • --batch-cutoff: Maximum waiting time. Optional. Valid values range from 0 to 60 seconds. The default is 1 second. The trigger groups messages for a period not exceeding batch-cutoff and sends them to a container. At the same time, the number of messages does not exceed batch-size.
  • --invoke-container-id: Container ID.
  • --invoke-container-service-account-id: Service account with rights to invoke the container.
  • --retry-attempts: Time to retry invoking the container if the current attempt fails. Optional. 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. Optional. Values can be from 1 to 5. The default is 1.
  • --dlq-queue-id: Dead Letter Queue ID. Optional.
  • --dlq-service-account-id: Service account with rights to write messages to the Dead Letter Queue. Optional.

Result:

id: a1s5msktij**********
folder_id: b1gmit33hg**********
created_at: "2022-10-24T15:19:15.353909857Z"
name: logging-trigger
rule:
  logging:
    log_group_id: e23bidnftl**********
    batch_settings:
      size: "1"
      cutoff: 1s
    invoke_container:
      container_id: bba5jb38o8**********
      service_account_id: aje03adgd2**********
      retry_settings:
        retry_attempts: "1"
        interval: 10s
      dead_letter_queue:
        queue-id: yrn:yc:ymq:ru-central1:b1gmit33ng**********:dlq
        service-account-id: aje3lebfem**********
status: ACTIVE

You can create a trigger for Cloud Logging using the create.

Checking the result

Make sure the trigger is working properly. To do this, view container logs that show information about invocations.

See also

  • Trigger for Cloud Logging that invokes a Cloud Functions function.

Was the article helpful?

Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
In this article:
  • Before you begin
  • Creating a trigger
  • Checking the result
  • See also