Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • URL shortener
    • Entering data into storage systems
    • Storing application runtime logs
    • Deploying a web application using the Java Servlet API
    • Developing a Slack bot
    • Developing a Telegram bot
    • Developing a custom integration in API Gateway
    • Developing CRUD APIs for movie services
    • Building a CI/CD pipeline in GitLab
    • Working with an API gateway via WebSocket
    • Creating an interactive serverless application using WebSocket
    • Automatically copying objects from one Object Storage bucket to another
    • Visualizing logs in Grafana using the Cloud Logging plugin
    • Canary release of a Cloud Functions function
    • Interactive debugging of Cloud Functions functions
    • Creating a Node.js function using TypeScript
    • Running a containerized app in Serverless Containers
    • Streaming Yandex Cloud Postbox events to Data Streams and analyzing them using DataLens
    • Using API Gateway to set up speech synthesis in SpeechKit
    • Connecting to YDB from a Cloud Functions function in Python
    • Connecting to a YDB database from a Cloud Functions function in Node.js
    • API Gateway protection with Smart Web Security
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Automatic data upload to Yandex SpeechSense using Yandex Workflows
    • Configuring responses in Cloud Logging and Yandex Cloud Functions
    • Setting up Workflows integration with Tracker, YandexGPT, and Yandex Cloud Postbox
    • Developing functions in Functions Framework and deploying them to Yandex Serverless Containers

In this article:

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

Canary release of a Cloud Functions function

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

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

To create a canary release:

  1. Get your cloud ready.
  2. Create a service account.
  3. Create a Cloud Functions function.
  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 billing account linked and it has the 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 outgoing traffic (see Yandex API Gateway pricing).
  • Fee for the number of function calls, computing resources allocated to 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. From the list of services, select Identity and Access Management.
  3. Click Create service account.
  4. Enter a name for the service account: canary-sa.
  5. Click Add role and select the editor role.
  6. Click Create.

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

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. Create the canary-sa service account:

    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 and the folder where you created it (folder_id).

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

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

  1. In the configuration file, describe the service account parameters:

    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 parameter.
    • folder_id: Folder ID. This is an optional parameter. By default, the value specified in the provider settings is used.
    • role: Role to assign.

    For more information about the yandex_iam_service_account resource parameters in Terraform, see the relevant provider documentation.

  2. Make sure the configuration files are correct.

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

    2. Run a check using this command:

      terraform plan
      

    If the configuration is specified correctly, the terminal will display information about the service account. If the configuration contains any errors, Terraform will point them out.

  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: type yes in the terminal and press Enter.

      The service account will then be created. You can check the new service account 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 Cloud Functions functionCreate a Cloud Functions function

Create two function versions:

  • Version for the current release.
  • Version for the canary release to be tested on a certain percentage of requests.

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

Add tagsAdd tags

Add the stable tag to the first function version and the canary tag to the second one.

CLI
Terraform
API

To add a version tag, run the 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 the yandex_function resource and specify the list of tags in tags = ["<tag_name>"] format.

    Example 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 the yandex_function resource properties, see the provider documentation.

  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
    

    The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  4. Apply the configuration changes:

    terraform apply
    
  5. Confirm the changes: type yes into the terminal and press Enter.

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. In the Specification section, add the 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, switch the Canary release toggle to on.

  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 the spec.yaml file:

    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 parameters of the yandex_api_gateway resource 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. The name should match the following format:

      • It must be from 2 to 63 characters long.
      • It may 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 the resource parameters in Terraform, see the relevant provider documentation.

  2. Make sure the configuration files are correct.

    1. In the command line, go 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 resources being created and their parameters. If the configuration contains any errors, Terraform will point them out.

  3. Deploy the cloud resources.

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

      terraform apply
      
    2. Confirm creating the resources: type yes in the terminal and press 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

Make several requests to the created API gateway. About one half of requests should be handled by the function version tagged canary.

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
Visualizing logs in Grafana using the Cloud Logging plugin
Next
Interactive debugging of Cloud Functions functions
© 2025 Direct Cursus Technology L.L.C.