[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud Functions](../../index.md) > [Step-by-step guides](../index.md) > Managing a function > Scaling a function > Adding scaling settings

# Adding function scaling settings

You can set the following:

* `zone_instances_limit`: Number of function instances per [availability zone](../../../overview/concepts/geo-scope.md).
* `zone_requests_limit`: Number of concurrent function calls per availability zone.
* `provisioned_instances_count`: Number of [provisioned instances](../../concepts/function.md#provisioned-instances).

You are [charged](../../pricing.md#provisioned-instances) separately for provisioned instance downtime and function execution time.

You can configure different scaling settings for different function [versions](../../concepts/function.md#version) using [tags](../../concepts/function.md#tag). Scaling settings will apply to the function version with the specified tag assigned. Function versions are scaled independently of each other.

The scaling settings must be within the [quotas](../../concepts/limits.md#functions-quotas).

{% note info %}

Scaling settings take effect within five minutes after they are configured.

{% endnote %}

{% list tabs group=instructions %}

- Management console {#console}

    1. In the [management console](https://console.yandex.cloud), navigate to the folder containing the function.
    1. Navigate to **Cloud Functions**.
    1. Select the function.
    1. Under **Version history**, hover over the version tag (e.g., ![image](../../../_assets/console-icons/gear.svg) or `$latest`) of the function you want to add scaling settings for.
    1. In the pop-up window, click **Add**.
    1. In the window that opens, specify the following:
        * **zone_instances_limit**: Number of function instances per availability zone.
        * **zone_requests_limit**: Number of concurrent function calls per availability zone.
        * **provisioned_instances_count**: Number of provisioned instances.
    1. Click **Save**.

- CLI {#cli}

    To configure scaling settings, run this command:

    ```bash
    yc serverless function set-scaling-policy \
      --id=<function_ID> \
      --tag=\$latest \
      --zone-instances-limit=1 \
      --zone-requests-limit=2 \
      --provisioned-instances-count=3
    ```

    Where:

    * `--id`: Function ID. To find out the ID, [get](function-list.md) the list of functions.
    * `--tag`: Function version [tag](../../concepts/function.md#tag).
    * `--zone-instances-limit`: Number of function instances.
    * `--zone-requests-limit`: Number of calls in progress.
    * `--provisioned-instances-count`: Number of provisioned instances.

    Result:

    ```bash
    function_id: d4eokpuol55h********
    tag: $latest
    zone_instances_limit: "1"
    zone_requests_limit: "2"
    provisioned_instances_count: "3"
    ```

- Terraform {#tf}

    With [Terraform](https://www.terraform.io/), 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](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
    
    For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

    If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
    
    
    To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.  

    To add scaling settings:

    1. In the configuration file, describe the resources you want to create:

       * `yandex_function`: Description of the function being created and its source code.
         * `name`: Function name.
         * `user_hash`: Any string to identify the function version. When you change the function, update this string as well. Updating this string triggers a function update.
         * `runtime`: Function [runtime](../../concepts/runtime/index.md).
         * `entrypoint`: Entry point in `<file_name_without_extension>.<handler_name>` format.
         * `memory`: Amount of memory allocated for the function, in MB.
         * `execution_timeout`: Maximum function execution time before 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.
       * `yandex_function_scaling_policy`: Description of function scaling settings.
         * `function_id`: Function ID.
         * `policy`: Scaling settings:
           * `policy.0.tag`: Function version [tag](../../concepts/function.md#tag).
           * `policy.0.zone_instances_limit`: Number of function instances.
           * `policy.0.zone_requests_limit`: Number of calls in progress.

        Here is an example of the configuration file structure:

        ```hcl
        resource "yandex_function" "test-function" {
          name               = "<function_name>"
          user_hash          = "<hash>"
          runtime            = "<runtime>"
          entrypoint         = "<entry_point>"
          memory             = "128"
          execution_timeout  = "10"
          service_account_id = "<service_account_ID>"
          content {
            zip_filename = "<path_to_ZIP_archive>"
          }
        }

        resource "yandex_function_scaling_policy" "my_scaling_policy" {
          function_id = "<function_ID>"
          policy {
            tag = "$latest"
            zone_instances_limit = 2
            zone_requests_limit  = 1
          }
        }
        ```

        For more on the properties of the `yandex_function_scaling_policy` resource, see [this provider guide](../../../terraform/resources/function_scaling_policy.md).

    1. Validate your configuration using this command:
        
       ```bash
       terraform validate
       ```

       If the configuration is valid, you will get this message:
        
       ```text
       Success! The configuration is valid.
       ```

    1. Run this command:

       ```
       terraform plan
       ```

       You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration. 

    1. Apply the configuration changes:

       ```bash
       terraform apply
       ```
    1. Type `yes` and press **Enter** to confirm the changes.

    You can check that the scaling settings are added using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:
    
    ```bash
    yc serverless function list-scaling-policies <function_name_or_ID>
    ```

- API {#api}

    To set scaling settings, use the [setScalingPolicy](../../functions/api-ref/Function/setScalingPolicy.md) REST API method for the [Function](../../functions/api-ref/Function/index.md) resource or the [FunctionService/SetScalingPolicy](../../functions/api-ref/grpc/Function/setScalingPolicy.md) gRPC API call.



{% endlist %}

## Useful links

* [Scaling a function](../../concepts/function.md#scaling)