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
    • Creating a Node.js function using TypeScript
  • 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 functions
  3. Managing function versions

Managing function versions

Written by
Yandex Cloud
,
improved by
amatol
  • Getting a list of functions
  • Creating a function version
    • Preparing a ZIP archive with the function code
    • Creating a function version
  • Getting information about a function version
    • Getting a list of function versions
    • Getting detailed information about a function version
  • Adding environment variables
  • Managing version tags
    • Adding a tag
    • Removing a tag

With function versioning, you can:

  • Creating a version
  • Get information about a function version
    • Get a list of function versions
    • Get detailed information about a function version
  • Adding environment variables
  • Manage version tags

You can change the function code using the Code editor.

Note

To ensure the integrity of version links, you can't update or delete function versions. For more information about relationships between resources, see Function.

Getting a list of functions

For function versioning, you need to know the name or unique ID of the function that the version belongs to. To find them, get a list of functions.

Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, go to the folder where you want to view a list of functions.
  2. Open Cloud Functions.
  3. On the left-hand panel, select Functions.

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 get a list of functions, run the command:

	yc serverless function list

Result:

	+----------------------+--------------------+----------------------+--------+
	|          ID          |        NAME        |      FOLDER ID       | STATUS |
	+----------------------+--------------------+----------------------+--------+
	| b097d9ous3gep99khe83 | my-beta-function   | aoek49ghmknnpj1ll45e | ACTIVE |
	+----------------------+--------------------+----------------------+--------+

You can get a list of functions using the list.

You can get a list of versions using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Creating a function version

To create versions of functions, you can use one of the code upload formats. A ZIP archive will be used for the example.

Warning

Files larger than 3.5 MB should be uploaded via Object Storage. For more information about limits, see Quotas and limits in Cloud Functions.

Preparing a ZIP archive with the function code

  1. Save the following code to a file named index.js:

    exports.handler = async function (event, context) {
        let name = 'World';
        if (event.queryStringParameters && event.queryStringParameters.name) {
            name = event.queryStringParameters.name
        }
        return {
            'statusCode': 200,
            'headers': {
                'Content-Type': 'text/plain'
            },
            'isBase64Encoded': false,
            'body': `Hello, ${name}!`
        }
    };
    
  2. Add index.js to the hello-js.zip archive.

Creating a function version

When creating a version, set the following parameters:

  • Runtime environment: Provides additional libraries and environment variables that can be accessed from the function code. It corresponds to the programming language that your function is written in. For more information, see Runtime environment.
  • Entry point: The function to be invoked as a handler. To read more about the handler, see Programming model.
  • Timeout: The maximum function execution time, after which the service will terminate its execution without waiting for a response. It includes the time of the first initialization when the function is first run.
Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, select the folder containing your function.
  2. Open Cloud Functions.
  3. Select the function to create a version of.
  4. Under Latest version, click Create in editor.
  5. Select the runtime environment. Use the Add files with code examples option.
  6. Prepare the function code:
    • Runtime environment: nodejs.
    • Method: ZIP archive.
    • File: hello-js.zip.
    • Entry point: index.handler.
  7. Set the version parameters:
    • Timeout: 5 sec.
    • RAM: 128 MB.
    • Service account: None selected.
    • Environment variables: None selected.
  8. In the top right-hand corner, click Create version.

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 function version, run the command:

yc serverless function version create \
  --function-name=my-nodejs-function \
  --runtime nodejs12 \
  --entrypoint index.handler \
  --memory 128m \
  --execution-timeout 5s \
  --source-path ./hello-js.zip

Where:

  • --function-name: The name of the function you want to create a version of.
  • --runtime: The runtime environment.
  • --entrypoint: The entry point specified in the <filename without extension>.<handler name> format.
  • --memory: The amount of RAM.
  • --execution-timeout: The maximum function execution time before the timeout is reached.
  • --source-path: A ZIP archive with the function code and required dependencies.

Result:

done (1s)
id: d4evvn8obisajd51plaq
function_id: d4elpv8pft639ku7k0u6
created_at: "2020-08-01T19:09:19.531Z"
runtime: nodejs12
entrypoint: index.handler
resources:
memory: "134217728"
execution_timeout: 5s
image_size: "4096"
status: ACTIVE
tags:
- $latest
log_group_id: ckg3qh8h363p40gmr9gn

You can create a function version using the createVersion.

You can create a function version using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Getting information about a function version

Getting a list of function versions

Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, select the folder containing your function.
  2. Open Cloud Functions.
  3. On the left-hand panel, select Functions.
  4. Select the function to get a list of versions for.
  5. Under Version history, you can find the list of function versions and their details.

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 get a list of function versions, run the command:

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

Result:

+----------------------+----------------------+----------+--------------+---------+---------------------+
|          ID          |     FUNCTION ID      | RUNTIME  |  ENTRYPOINT  |  TAGS   |     CREATED AT      |
+----------------------+----------------------+----------+--------------+---------+---------------------+
| b09u830mb1n32a7rj0n8 | b097d9ous3gep99khe83 | python37 | test.handler | $latest | 2019-06-13 09:23:23 |
| b09ch6pmpohfc9sogj5f | b097d9ous3gep99khe83 | python37 | test.handler | beta    | 2019-06-13 09:12:38 |
+----------------------+----------------------+----------+--------------+---------+---------------------+

You can get a list of function versions using the listVersions API method.

You can get a list of versions using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Getting detailed information about a function version

Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, select the folder containing your function.
  2. Open Cloud Functions.
  3. On the left-hand panel, select Functions.
  4. Select the function to get a list of versions for.
  5. Under Version history, you can find the list of function versions and their details.

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 get detailed information about a function version by:

  • ID, run the command:

    yc serverless function version get <version ID>
    

    Result:

    id: b09u830mb1n32a7rj0n8
    function_id: b097d9ous3gep99khe83
    created_at: "2019-06-13T09:23:23.383Z"
    runtime: python37
    entrypoint: test.handler
    resources:
      memory: "134217728"
    execution_timeout: 5s
    image_size: "4096"
    status: ACTIVE
    tags:
    - $latest
    log_group_id: eolv6578frac08uh5h6s
    
  • TAGS, run the command:

    yc serverless function version get-by-tag --function-name <function name> --tag <tag>
    

    Result:

    id: b09ch6pmpohfc9sogj5f
    function_id: b097d9ous3gep99khe83
    created_at: "2019-06-13T09:12:38.464Z"
    runtime: python37
    entrypoint: test.handler
    resources:
      memory: "134217728"
    execution_timeout: 5s
    image_size: "4096"
    status: ACTIVE
    tags:
    - beta
    log_group_id: eolv6578frac08uh5h6s
    

You can get details of the function version using the getVersion API method.

You can get details about a function version using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Adding environment variables

When you add environment variables, a new version of the function is created. You can't add variables to an existing version.

Management console
CLI
API
Yandex Cloud Toolkit
  1. In the management console, select the folder containing your function.
  2. Open Cloud Functions.
  3. Select the function whose version you want to add an environment variable for.
  4. Go to the Editor tab.
  5. Under Parameters, specify the environment variable and click Add. You can add multiple environment variables.
  6. Click Create version. A new version of the function with the specified environment variables is created.

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 add environment variables, run the command:

Warning

If the previous version contained environment variables, this command overwrites them.

yc serverless function version create \
  --function-name=<function name> \
  --runtime <runtime environment> \
  --entrypoint <entry point> \
  --memory 128m \
  --execution-timeout 5s \
  --source-version-id <version ID> \
  --environment <environment variables>

Where:

  • --function-name: The function name.
  • --runtime: The runtime environment.
  • --entrypoint: The entry point specified in the . format.
  • --memory: The amount of RAM.
  • --execution-timeout: The maximum function execution time before the timeout is reached.
  • --source-version-id: The ID of the function version to copy the code of.
  • --environment: Environment variables in key=value format. You can specify multiple pairs separated by commas.

You can add environment variables using the createVersion.

You can add environment variables using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Managing version tags

When creating a new version, it's assigned the $latest tag by default. You can add and remove version tags.

To access the function version, use its unique ID. For information about how to find the unique version ID, see Getting a list of function versions.

Adding a tag

CLI
API
Yandex Cloud Toolkit

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 add a version tag, run the command:

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

Result:

id: b09ch6pmpohfc9sogj5f
function_id: b097d9ous3gep99khe83
created_at: "2019-06-13T09:12:38.464Z"
runtime: python37
entrypoint: test.handler
resources:
  memory: "134217728"
execution_timeout: 5s
image_size: "4096"
status: ACTIVE
tags:
- beta
- first
log_group_id: eolv6578frac08uh5h6s

You can add a tag using the setTag.

You can add a tag using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Removing a tag

CLI
API
Yandex Cloud Toolkit

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 remove a version tag, run the command:

yc serverless function version remove-tag --id <version ID> --tag <tag>

Result:

id: b09ch6pmpohfc9sogj5f
function_id: b097d9ous3gep99khe83
created_at: "2019-06-13T09:12:38.464Z"
runtime: python37
entrypoint: test.handler
resources:
  memory: "134217728"
execution_timeout: 5s
image_size: "4096"
status: ACTIVE
tags:
- beta
log_group_id: eolv6578frac08uh5h6s

You can remove a tag using the removeTag.

You can delete a tag using the Yandex Cloud Toolkit plugin for the IDE family on the IntelliJ platform from JetBrains.

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Getting a list of functions
  • Creating a function version
  • Preparing a ZIP archive with the function code
  • Creating a function version
  • Getting information about a function version
  • Getting a list of function versions
  • Getting detailed information about a function version
  • Adding environment variables
  • Managing version tags
  • Adding a tag
  • Removing a tag