Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Cloud Functions
  • Comparison with other Yandex Cloud services
  • Getting started
    • Overview
    • Creating a function
      • Overview
      • Node.js
      • Python
      • Go
      • PHP
      • Bash
      • Java
    • Creating a trigger
      • Overview
      • Timer
      • Trigger for Message Queue
      • Trigger for Object Storage
      • Trigger for Container Registry
      • Trigger for Cloud Logs
      • Trigger for Cloud Logging
      • Trigger for Yandex IoT Core
      • Trigger for budgets
      • Trigger for Data Streams
  • Step-by-step instructions
    • All instructions
    • Using functions to get an IAM token for a service account
    • Connecting to managed databases from functions
    • Managing rights to access functions
    • Managing functions
      • Creating a function
      • Managing function versions
      • Working in the code editor
      • Invoking a function
      • Updating a function
      • Scaling a function
      • Function monitoring
      • Viewing the execution log
      • Deleting a function
    • Managing triggers
      • Getting information about a trigger
      • 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 Logs
      • Creating a trigger for Cloud Logging
      • Creating a trigger for Yandex IoT Core
      • Creating a trigger for budgets
      • Creating a trigger for Data Streams
      • Updating a trigger
      • Trigger monitoring
      • Deleting a trigger
  • Concepts
    • Overview
    • Function
    • Invoking a function
    • Runtime environment
      • Overview
      • Environment
      • Execution context
      • Preloaded runtime environment
    • Builder
    • Trigger
      • Overview
      • Timer
      • Trigger for Message Queue
      • Trigger for Object Storage
      • Trigger for Container Registry
      • Trigger for Cloud Logs
      • Trigger for Cloud Logging
      • Trigger for Yandex IoT Core
      • Trigger for budgets
      • Trigger for Data Streams
    • Dead Letter Queue
    • Log groups
    • Backups
    • Quotas and limits
  • Developing in Node.js
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Python
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Go
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in PHP
    • Overview
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
  • Developing in Bash
    • Overview
    • Request handler
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in Java
    • Overview
    • Programming model
      • Overview
      • Function interface
      • YcFunction interface
      • HttpServlet class
      • Spring Boot
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Developing in R
    • Overview
    • Programming model
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
  • Developing in C#
    • Overview
    • Programming model
      • Overview
      • Function interface
      • YcFunction interface
    • Managing dependencies
    • Request handler
    • Invocation context
    • Logging
    • Handling errors
    • Using the SDK
  • Practical guidelines
    • Creating skills for Alice
    • Deploying a web application
    • Developing a skill for Alice and a website with authorization
    • Writing data from a device to Managed Service for PostgreSQL
    • Developing a Slack bot
    • Developing a Telegram bot
    • Connecting to a YDB database from a Python function
    • Connecting to a YDB database from a function in Node.js
    • Converting a video to a GIF in Python
  • Pricing policy
  • Access management
  • API Functions reference
    • Authentication in the API
    • gRPC
      • Overview
      • FunctionService
      • OperationService
    • REST
      • Overview
      • Function
        • Overview
        • create
        • createVersion
        • delete
        • get
        • getVersion
        • getVersionByTag
        • list
        • listAccessBindings
        • listOperations
        • listRuntimes
        • listScalingPolicies
        • listTagHistory
        • listVersions
        • removeScalingPolicy
        • removeTag
        • setAccessBindings
        • setScalingPolicy
        • setTag
        • update
        • updateAccessBindings
  • API Triggers reference
    • Authentication in the API
    • gRPC
      • Overview
      • TriggerService
      • OperationService
    • REST
      • Overview
      • Trigger
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • pause
        • resume
        • update
  • Questions and answers
  1. Step-by-step instructions
  2. Managing triggers
  3. Creating a trigger for budgets

Creating a trigger for budgets

Written by
Yandex.Cloud
,
improved by
AlexElin
  • Before you start
  • Creating a trigger
  • Checking the result

Create a trigger for budgets that calls a Cloud Functions function or Serverless Containers container when threshold values are exceeded.

Before you start

To create a trigger, you need:

  • A function or a container the trigger will launch.

    • If you don't have a function:

      • Create a function.
      • Create a function version.
    • If you don't have a container:

      • Create a container.
      • Create a container revision.
  • A budget which, when exceeded, a trigger is fired. If you don't have a budget, create one.

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

  • Service accounts with rights to invoke a function or a 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.

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 Cloud Functions.

  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 Budget.
    • Choose what the trigger will launch — a function or a container.
  6. Under Budget settings, select your billing account and budget. You can select All budgets.

  7. If the trigger launches:

    • A function, select one under Function settings and specify:

      • Tag of the function version;
      • A service account to be used to invoke the function.
    • A container, select one under Container settings and specify:

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

    • In the Interval field, specify the time after which the function or the container will 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.
  9. (optional) Under Dead Letter Queue settings, select the Dead Letter Queue and the service account with write privileges to this queue.

  10. 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 launches a function, run the command:

yc serverless trigger create billing-budget \
  --name <trigger name> \
  --billing-account-id <billing account ID> \
  --budget-id <budget ID> \
  --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>

Where:

  • --name: Trigger name.
  • --billing-account-id: Billing account ID.
  • --budget-id: Budget ID.
  • --invoke-function-id: Function ID.
  • --invoke-function-service-account-id: ID of the service account with rights to invoke the function.
  • --retry-attempts: The time after which the function will be invoked again 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: a1sfe084v4se4morbu2i
folder_id: b1g88tflru0ek1omtsu0
created_at: "2019-12-04T08:45:31.131391Z"
name: budget-trigger
rule:
  billing-budget:
    billing-account-id: dn2char50j**********
    budget-id: dn2jnshmdlc1********
    invoke_function:
      function_id: d4eofc7n0m03********
      function_tag: $latest
      service_account_id: aje3932acd0c********
      retry_settings:
        retry_attempts: "1"
        interval: 10s
      dead_letter_queue:
        queue-id: yrn:yc:ymq:ru-central1:aoek49ghmknn********:dlq
        service-account-id: aje3932acd0c********
status: ACTIVE

You can create a trigger using the API create.

Checking the result

Make sure the trigger is working properly. To do this, view function logs or container logs: they show information about calls.

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Before you start
  • Creating a trigger
  • Checking the result