Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Yandex Cloud Functions
  • Comparison with other Yandex Cloud services
    • All guides
    • Using functions to get an IAM token for a service account
    • Connecting to managed databases from functions
      • Creating 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 budgets
      • Creating a trigger for Data Streams
      • Creating an email trigger
    • Viewing operations with service resources
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Creating a trigger
  • Checking the result
  • See also
  1. Step-by-step guides
  2. Creating a trigger
  3. Creating a trigger for Message Queue

Create a trigger for Message Queue that sends messages to the Cloud Functions function

Written by
Yandex Cloud
Improved by
Danila N.
Updated at July 29, 2025
  • Getting started
  • Creating a trigger
  • Checking the result
  • See also

Create a trigger for a message queue in Message Queue and process the messages using the Cloud Functions function.

Warning

  • You can only create a trigger for a standard message queue.
  • The trigger must be in the same cloud as the queue from which it reads messages.
  • You can create only one trigger for each message queue.

Getting startedGetting started

To create a trigger, you need:

  • A function to be invoked by the trigger. If you do not have a function:

    • Create a function.
    • Create a function version.
  • Service accounts with the following permissions:

    • To invoke a function.
    • To read from the queue the trigger receives messages from.

    You can use the same service account or different ones. If you do not have a service account, create one.

  • Message queue the trigger will collect messages from. If you do not have a queue, create one.

Creating a triggerCreating a trigger

Note

The trigger is initiated within 5 minutes of being created.

Management console
CLI
Terraform
API
  1. In the management console, select the folder where you want to create a trigger.

  2. Select Cloud Functions.

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

  4. Click Create trigger.

  5. Under Basic settings:

    • Enter a name and description for the trigger.
    • In the Type field, select Message Queue.
    • In the Launched resource field, select Function.
  6. Under Message Queue message settings, select a message queue and a service account with permissions to read messages from this queue.

  7. Under Batch message settings, specify:

    • Waiting time, s. The values may range from 0 to 20 seconds. The default value is 10 seconds.
    • Batch size. The values may range from 1 to 1,000. The default value is 1.

    The trigger groups messages for a period of time not exceeding the specified timeout and sends them to a function. The number of messages cannot exceed the specified batch size.

  8. Under Function settings, select a function and specify:

    • Function version tag.
    • Service account to invoke the function under.
  9. Click Create trigger.

If you do not have the Yandex Cloud CLI installed yet, install and initialize it.

By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.

To create a trigger that invokes a function, run this command:

yc serverless trigger create message-queue \
  --name <trigger_name> \
  --queue <queue_ID> \
  --queue-service-account-id <service_account_ID> \
  --invoke-function-id <function_ID> \
  --invoke-function-service-account-id <service_account_ID> \
  --batch-size <message_group_size> \
  --batch-cutoff <maximum_timeout>

Where:

  • --name: Trigger name.

  • --queue: Queue ID

    To find out the queue ID:

    1. In the management console, go the folder containing the queue.
    2. Select Message Queue.
    3. Select the queue.
    4. You can see the queue ID under General information in the ARN field.
  • --invoke-function-id: Function ID.

  • --queue-service-account-name: ID of the service account with permissions to read messages from the queue.

  • --invoke-function-service-account-id: ID of the service account with the permissions to invoke the function.

  • --batch-size: Message batch size. This is an optional parameter. The values may range from 1 to 1,000. The default value is 1.

  • --batch-cutoff: Maximum wait time. This is an optional parameter. The values may range from 0 to 20 seconds. The default value is 10 seconds. The trigger groups messages for a period not exceeding batch-cutoff and sends them to a function. The number of messages cannot exceed batch-size.

Result:

id: dd0cspdch6**********
folder_id: aoek49ghmk**********
created_at: "2019-08-28T12:14:45.762915Z"
name: ymq-trigger
rule:
  message_queue:
    queue_id: yrn:yc:ymq:ru-central1:aoek49ghmk**********:my-mq
    service_account_id: bfbqqeo6jk**********
    batch_settings:
      size: "1"
      cutoff: 10s
    invoke_function:
      function_id: b09e5lu91t**********
      function_tag: $latest
      service_account_id: bfbqqeo6j**********
status: ACTIVE

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the relevant documentation on the Terraform website or its mirror.

If you do not have Terraform yet, install it and configure the Yandex Cloud provider.

To create a trigger for Message Queue:

  1. In the configuration file, describe the trigger parameters:

    resource "yandex_function_trigger" "my_trigger" {
      name        = "<trigger_name>"
      description = "<trigger_description>"
      function {
        id                 = "<function_ID>"
        service_account_id = "<service_account_ID>"
      }
      message_queue {
        queue_id           = "<queue_ID>"
        service_account_id = "<service_account_ID>"
        batch_size         = "<message_group_size>"
        batch_cutoff       = "<maximum_timeout>"
    }
    

    Where:

    • name: Trigger name. The name format is as follows:

      • It must be from 2 to 63 characters long.
      • It can only contain lowercase Latin letters, numbers, and hyphens.
      • It must start with a letter and cannot end with a hyphen.
    • description: Trigger description.

    • function: Function parameters:

      • id: Function ID.
      • service_account_id: ID of the service account with the permissions to invoke the function.
    • message_queue: Trigger parameters:

      • queue_id: Message queue ID.

        To find out the queue ID:

        1. In the management console, go the folder containing the queue.
        2. Select Message Queue.
        3. Select the queue.
        4. You can see the queue ID under General information in the ARN field.
      • service_account_id: ID of the service account with permissions to read messages from the queue.

      • batch_size: Message batch size. This is an optional parameter. The values may range from 1 to 1,000. The default value is 1.

      • batch_cutoff: Maximum wait time. This is an optional parameter. The values may range from 0 to 20 seconds. The default value is 10 seconds. The trigger groups messages for a period not exceeding batch-cutoff and sends them to a function. The number of messages cannot exceed batch-size.

    For more information about the yandex_function_trigger resource parameters, see the provider documentation.

  2. Create resources:

    1. In the terminal, go to the directory where you edited the configuration file.

    2. Make sure the configuration file is correct using this command:

      terraform validate
      

      If the configuration is correct, you will get this message:

      Success! The configuration is valid.
      
    3. Run this command:

      terraform plan
      

      You will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.

    4. Apply the changes:

      terraform apply
      
    5. Type yes and press Enter to confirm the changes.

    Terraform will create all the required resources. You can check the new resources using the management console or this CLI command:

    yc serverless trigger list
    

To create a trigger for Yandex Message Queue, use the create REST API method for the Trigger resource or the TriggerService/Create gRPC API call.

Checking the resultChecking the result

Cloud Functions
Message Queue

Check that the trigger operates correctly. Do it by viewing function logs that present information on invocations.

Check that the number of enqueued messages is decreasing. To do this, view the queue statistics:

  1. In the management console, select Message Queue.
  2. Select the queue that you created the trigger for.
  3. Go to Monitoring. Check the Messages in the queue chart.

See alsoSee also

  • Creating a trigger for Message Queue that sends messages to a Serverless Containers container
  • Creating a trigger for Message Queue that sends messages to WebSocket connections

Was the article helpful?

Previous
Creating a timer
Next
Creating a trigger for Object Storage
© 2025 Direct Cursus Technology L.L.C.