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
    • Education and Science
    • 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 tutorials
    • Creating a skill for Alice
    • Deploying a web application
    • Creating a skill for Alice and a website with authorization
    • Writing data from a device into a database
    • Writing load balancer logs to 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
    • Creating a Node.js function using TypeScript
    • Developing a custom integration
    • Creating a budget trigger that invokes a function to stop a VM
    • Creating an interactive serverless application using WebSocket
    • Automatically copying objects from one Object Storage bucket to another
    • Running computations on a schedule in DataSphere
    • Interactive debugging of functions
    • Regular asynchronous recognition of audio files from Object Storage
    • Canary release of Cloud Functions
    • Deploying a fault-tolerant architecture with preemptible VMs
    • Creating triggers that invoke a function to stop a VM and send a Telegram notification
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Status monitoring of geographically distributed devices
    • Sensor reading monitoring and event notifications
    • Emulating multiple IoT devices
    • Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them using Yandex DataLens
    • URL shortener
    • Yandex Tracker: data export and visualization
    • Running computations in DataSphere using the API
    • Developing a Telegram bot for text and audio recognition
    • Configuring responses in Yandex Cloud Logging and Cloud Functions
    • Developing functions in Functions Framework and deploying them to Yandex Serverless Containers
    • Configuring CI/CD with SourceCraft
    • Creating an AI agent with Cloud Functions
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Create a service account
  • Create a function in Cloud Functions
  • Add tags
  • Create an API gateway
  • Test the application
  • How to delete the resources you created
  1. Tutorials
  2. Canary release of Cloud Functions

Canary release of Cloud Functions

Written by
Yandex Cloud
Improved by
Danila N.
Updated at July 14, 2025
  • Getting started
    • Required paid resources
  • Create a service account
  • Create a function in Cloud Functions
  • Add tags
  • Create an API gateway
  • Test the application
  • How to delete the resources you created

Create a canary release of a function in Cloud Functions using API Gateway.

To create a canary release:

  1. Get your cloud ready.
  2. Create a service account.
  3. Create a function in Cloud Functions.
  4. Add tags.
  5. Create an API gateway.
  6. Test your application.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a linked billing account with an ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The cost of resources to support a web application includes:

  • Fee for the number of requests to the API gateway and outbound traffic (see Yandex API Gateway pricing).
  • Fee for function invocation count, computing resources allocated to run the function, and outbound traffic (see Yandex Cloud Functions pricing).

Create a service accountCreate a service account

Management console
CLI
Terraform
API
  1. In the management console, select the folder where you want to create a service account.
  2. In the list of services, select Identity and Access Management.
  3. Click Create service account.
  4. Enter the service account name: canary-sa.
  5. Click Add role and select editor.
  6. Click Create.

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.

  1. Create a service account named canary-sa:

    yc iam service-account create --name canary-sa
    

    Result:

    id: nfersamh4sjq********
    folder_id: b1gc1t4cb638********
    created_at: "2023-09-21T10:36:29.726397755Z"
    name: canary-sa
    

    Save the ID of the canary-sa service account (id) and the ID of the folder where you created it (folder_id).

  2. Assign the editor role for the folder to the service account:

    yc resource-manager folder add-access-binding <folder_ID> \
      --role editor \
      --subject serviceAccount:<service_account_ID>
    

    Result:

    done (1s)
    

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

  1. In the configuration file, define the service account properties:

    resource "yandex_iam_service_account" "canary-sa" {
      name        = "canary-sa"
      folder_id   = "<folder_ID>"
    }
    
    resource "yandex_resourcemanager_folder_iam_member" "editor" {
      folder_id = "<folder_ID>"
      role      = "editor"
      member    = "serviceAccount:${yandex_iam_service_account.canary-sa id}"
    }
    

    Where:

    • name: Service account name. This is a required setting.
    • folder_id: Folder ID. This is an optional setting. It defaults to the value defined by the provider.
    • role: Role being assigned.

    For more information about yandex_iam_service_account properties, see this Terraform article.

  2. Make sure the configuration files are correct.

    1. In the command line, navigate to the directory where you created the configuration file.

    2. Run a check using this command:

      terraform plan
      

    If you described the configuration correctly, the terminal will display information about the service account. If the configuration contains any errors, Terraform will show them.

  3. Deploy the cloud resources.

    1. If the configuration does not contain any errors, run this command:

      terraform apply
      
    2. Confirm creating the service account by typing yes in the terminal and pressing Enter.

      This will create the service account. You can check it using the management console or this CLI command:

      yc iam service-account list
      

To create a service account, use the create REST API method for the ServiceAccount resource or the ServiceAccountService/Create gRPC API call.

To assign the editor role for a folder to a service account, use the setAccessBindings method for the ServiceAccount resource or the ServiceAccountService/SetAccessBindings gRPC API call.

Create a function in Cloud FunctionsCreate a function in Cloud Functions

Create two function versions:

  • Current release version.
  • Canary release version to test on a certain percentage of requests.

You can use a custom function or create any function from the list.

Add tagsAdd tags

Tag the first function version as stable and the second one as canary.

CLI
Terraform
API

To tag a version, run this command:

yc serverless function version set-tag --id <version_ID> --tag <tag>

Result:

id: b09ch6pmpohf********
function_id: b097d9ous3ge********
created_at: "2023-08-22T09:12:38.464Z"
runtime: python311
entrypoint: test.handler
resources:
  memory: "134217728"
execution_timeout: 5s
image_size: "4096"
status: ACTIVE
tags:
  - $latest
  - stable

To add a version tag:

  1. In the configuration file, add the tags section for yandex_function and list the tags you want to add in the following format: tags = ["<tag_name>"].

    Example of a function description in the Terraform configuration:

    resource "yandex_function" "test-function" {
        name               = "canary-function"
        user_hash          = "canary-function"
        runtime            = "python311"
        entrypoint         = "main"
        memory             = "128"
        execution_timeout  = "10"
        service_account_id = "<service_account_ID>"
        tags               = ["my_tag"]
        content {
            zip_filename = "<path_to_ZIP_archive>"
        }
    }
    

    For more information about yandex_function properties, see this Terraform article.

  2. Check the configuration 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.

You can check the new tags using the management console or this CLI command:

yc serverless function version list --function-name <function_name>

To add a function version tag, use the setTag REST API method for the Function resource or the FunctionService/SetTag gRPC API call.

Create an API gatewayCreate an API gateway

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

  2. In the list of services, select API Gateway.

  3. Click Create API gateway.

  4. In the Name field, enter canary.

  5. Under Specification, add the following specification:

    openapi: 3.0.0
    info:
      title: Sample API
      version: 1.0.0
    
    x-yc-apigateway:
      variables:
        function.tag:
          default: "stable"
          enum:
            - "stable"
            - "canary"
    
    paths:
      /:
        get:
          x-yc-apigateway-integration:
            type: cloud_functions
            function_id: <function_ID>
            tag: "${var.function.tag}"
            service_account_id: <service_account_ID>
    
  6. Under Variable settings, enable Canary release.

  7. In the Share of requests in canary release field, specify 50.

  8. In the Variables for canary release field, specify function.tag=canary.

  9. Click Create.

  1. Save the following specification to spec.yaml:

    openapi: 3.0.0
    info:
      title: Sample API
      version: 1.0.0
    
    x-yc-apigateway:
      variables:
        function.tag:
          default: "stable"
          enum:
            - "stable"
            - "canary"
    
    paths:
      /:
        get:
          x-yc-apigateway-integration:
            type: cloud_functions
            function_id: <function_ID>
            tag: "${var.function.tag}"
            service_account_id: <service_account_ID>
    
  2. Run this command:

    yc serverless api-gateway create --name canary --spec=spec.yaml --canary-weight=50 --canary-variables function.tag=canary
    

    Where:

    • --name: API gateway name.
    • --spec: Specification file.
    • --canary-weight: Percentage of requests in the canary release.
    • --canary-variables: Variables for the canary release.

    Result:

    done (5s)
    id: d5d1ud9bli1e********
    folder_id: b1gc1t4cb638********
    created_at: "2023-09-25T16:01:48.926Z"
    name: canary
    status: ACTIVE
    domain: d5dm1lba80md********.i9******.apigw.yandexcloud.net
    log_group_id: ckgefpleo5eg********
    connectivity: {}
    log_options:
      folder_id: b1gc1t4cb638********
    canary:
      weight: "50"
      variables:
        function.tag:
          string_value: canary
    

To create an API gateway:

  1. Describe the yandex_api_gateway properties in the configuration file:

    resource "yandex_api_gateway" "canary-api-gateway" {
      name        = "canary"
      canary {
        weight    = 50
        variables = {
          function.tag = "canary"
        }
      }
      spec = <<-EOT
        openapi: 3.0.0
         info:
           title: Sample API
           version: 1.0.0
    
         x-yc-apigateway:
           variables:
             function.tag:
               default: "stable"
               enum:
                 - "stable"
                 - "canary"
    
         paths:
           /:
             get:
               x-yc-apigateway-integration:
                 type: cloud_functions
                 function_id: <function_ID>
                 tag: "${var.function.tag}"
                 service_account_id: <service_account_ID>
      EOT
    }
    

    Where:

    • name: API gateway name. Follow these naming requirements:

      • 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.
    • canary.0.weight: Percentage of requests in the canary release.

    • canary.0.variables: Variables for the canary release.

    • spec: API gateway specification.

    For more information about yandex_api_gateway properties, see this Terraform article.

  2. Make sure the configuration files are correct.

    1. In the command line, navigate to the directory where you created the configuration file.

    2. Run a check using this command:

      terraform plan
      

    If you described the configuration correctly, the terminal will display a list of the new resources and their properties. If the configuration contains any errors, Terraform will show them.

  3. Deploy the cloud resources.

    1. If the configuration does not contain any errors, run this command:

      terraform apply
      
    2. Confirm creating the resources by typing yes in the terminal and pressing Enter.

      This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console or these CLI commands:

      yc serverless api-gateway get <API_gateway_name>
      

To create an API gateway, use the create REST API method for the ApiGateway resource or the ApiGatewayService/Create gRPC API call.

Test the applicationTest the application

Send several requests to the created API gateway. The function version tagged canary should handle about half of your requests.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Delete the API gateway.
  2. Delete the function.

Was the article helpful?

Previous
Regular asynchronous recognition of audio files from Object Storage
Next
Deploying a fault-tolerant architecture with preemptible VMs
© 2025 Direct Cursus Technology L.L.C.