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
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
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 function
      • Creating a function version
    • Viewing operations with service resources
  • Tools
  • Pricing policy
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes
  • FAQ

In this article:

  • Preparing a ZIP archive with the function code
  • Creating a function version
  1. Step-by-step guides
  2. Creating a function
  3. Creating a function version

Creating a function version

Written by
Yandex Cloud
Improved by
amatol
Updated at May 5, 2025
  • Preparing a ZIP archive with the function code
  • Creating a function version

To create a function version, 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 codePreparing 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 the index.js file into the hello-js.zip ZIP archive.

    Note

    If you use the Finder context menu to create a ZIP archive on macOS, a service directory titled __MACOSX is automatically added to the archive. This directory may cause errors when you build functions. To delete this directory from your ZIP archive, use the command line to navigate to the folder containing the archive and run this command:

    zip -d <archive_name>.zip "__MACOSX/*"
    

Creating a function versionCreating 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 your function is written in. For more information, see Runtime environment.
  • Entry point: Function to be invoked as a handler.
  • Timeout: 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
Terraform
API
Yandex Cloud Toolkit
  1. In the management console, select the folder containing the function.
  2. Select Cloud Functions.
  3. Select the function to create a version of.
  4. Under Last version, click Сreate in editor.
  5. Select the runtime environment. Disable the Add files with code examples option.
  6. Click Continue.
  7. Prepare the function code:
    • Runtime environment: nodejs18.
    • Method: ZIP archive.
    • File: hello-js.zip.
    • Entry point: index.handler.
  8. Set the version parameters:
    • Timeout: 5.
    • Memory: 128 MB.
    • Service account: Not selected.
    • Environment variables: Not selected.
  9. Click Save changes.

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.

To create a function version, run the command:

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

Where:

  • --function-name: Name of the function whose version you want to create.
  • --runtime: Runtime environment.
  • --entrypoint: Entry point in the following format: <file_name_without_extension>.<listener_name>.
  • --memory: Amount of RAM.
  • --execution-timeout: Maximum running time of the function until timeout.
  • --source-path: ZIP archive with the function code and required dependencies.

Result:

done (1s)
id: d4evvn8obisa********
function_id: d4elpv8pft63********
created_at: "2020-08-01T19:09:19.531Z"
runtime: nodejs18
entrypoint: index.handler
resources:
  memory: "134217728"
execution_timeout: 5s
image_size: "4096"
status: ACTIVE
tags:
  - $latest
log_options:
  folder_id: b1g681qpemb4********

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 documentation on the Terraform website or mirror website.

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

To create a new function version:

  1. Open the Terraform configuration file and change the function parameters:

    • yandex_function: Description of the function being created and its source code.
      • name: Function name.
      • description: Text description of the function.
      • user_hash: Any string to identify the function version. When the function changes, update this string, too. The function will update when this string is updated.
      • runtime: Function runtime environment.
      • entrypoint: Function name in the source code that will serve as an entry point to applications.
      • memory: Amount of memory allocated for the function, in MB.
      • execution_timeout: Function running timeout.
      • service_account_id: ID of the service account you want to use to invoke the function.
      • content: Function source code.
        • content.0.zip_filename: Name of the ZIP archive containing the function source code.

    Here is an example of the configuration file structure:

    resource "yandex_function" "test-function" {
        name               = "test-function"
        description        = "Test function"
        user_hash          = "first-function"
        runtime            = "nodejs18"
        entrypoint         = "main"
        memory             = "128"
        execution_timeout  = "10"
        service_account_id = "<service_account_ID>"
        content {
            zip_filename = "<path_to_ZIP_archive>"
        }
    }
    

    Note

    If the function name or description is changed, the version will not be created.

    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
    

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

  4. Apply the changes:

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

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

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

To create a function version, use the createVersion REST API method for the Function resource or the FunctionService/CreateVersion gRPC API call.

Request example

To use the examples, install cURL and authenticate in the API.

  1. Upload the hello-js.zip archive with the function version code to your Object Storage bucket.

  2. Prepare a file named body.json with the following request body:

    {
      "functionId": "<function_ID>",
      "runtime": "nodejs18",
      "entrypoint": "index.handler",
      "resources": {
        "memory": "134217728"
      },
      "executionTimeout": "5s",
      "serviceAccountId": "<service_account_ID>",
      "package": {
        "bucketName": "<bucket_name>",
        "objectName": "hello-js.zip"
      },
    }
    

    Where:

    • functionId: ID of the function the version of which you want to create.
    • runtime: Runtime environment.
    • entrypoint: Entry point in the following format: <file_name_without_extension>.<listener_name>.
    • memory: Amount of RAM.
    • executionTimeout: Maximum running time of the function until timeout.
    • serviceAccountId: ID of the service account with a role that allows bucket data reads.
    • bucketName: Name of the bucket where you uploaded the ZIP archive with the function code and required dependencies.
    • objectName: Key of the bucket object that contains the function code.
  3. Run this request:

    export IAM_TOKEN=<IAM_token>
    curl \
        --request POST \
        --header "Authorization: Bearer ${IAM_TOKEN}" \
        --data "@<body.json_file_path>" \
        https://serverless-functions.api.cloud.yandex.net/functions/v1/versions
    

    Result:

    {
     "done": false,
     "metadata": {
      "@type": "type.googleapis.com/yandex.cloud.serverless.functions.v1.CreateFunctionVersionMetadata",
      "functionVersionId": "d4e25m0gila4********"
     },
     "id": "d4edk0oobcc9********",
     "description": "Create function version",
     "createdAt": "2023-10-11T11:22:21.286786431Z",
     "createdBy": "ajeol2afu1js********",
     "modifiedAt": "2023-10-11T11:22:21.286786431Z"
    }
    

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

Note

To ensure the integrity of version links, you cannot update function versions. For more information about the resource relationships, see Function.

Was the article helpful?

Previous
Creating a function
Next
Invoking a function
Yandex project
© 2025 Yandex.Cloud LLC