[Yandex Cloud documentation](../../../index.md) > [Tutorials](../../index.md) > [Serverless technologies](../index.md) > Serverless-based workflows and automation > [Scheduled instance group scaling](index.md) > Management console, CLI, and API

# Scheduled instance group scaling with the management console

To set up [scheduled scaling for an instance group](index.md):

1. [Get your cloud ready](#before-begin).
1. [Create an instance group](#create-ig).
1. [Create Cloud Functions resources](#create-sf-resources).
1. [Test instance group scaling](#test-scale).

If you no longer need the resources you created, [delete them](#clear-out).

## Get your cloud ready {#before-begin}

Sign up for Yandex Cloud and create a [billing account](../../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../../billing/quickstart/index.md) and [link](../../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../../resource-manager/concepts/resources-hierarchy.md).

In our example, we will use a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) named `example-folder`.

### Required paid resources {#paid-resources}

The infrastructure support cost includes:
* Fee for [disks](../../../compute/concepts/disk.md) and continuously running [VMs](../../../compute/concepts/vm.md) (see [Compute Cloud pricing](../../../compute/pricing.md)).
* Fee for [function calls](../../../functions/concepts/function.md), computing resources allocated for the function, and outgoing traffic (see [Cloud Functions pricing](../../../functions/pricing.md)).

## Create the auxiliary resources {#create-aux-resources}

### Create a service account {#create-sa}

The [service account](../../../iam/concepts/users/service-accounts.md) will be linked to the Compute Cloud instance group and the Cloud Functions function.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Identity and Access Management**.
  1. Click **Create service account**.
  1. Name the [service account](../../../iam/concepts/users/service-accounts.md): `vm-scale-scheduled-sa`.
  1. Click ![image](../../../_assets/console-icons/plus.svg) **Add role** and select these [roles](../../../iam/concepts/access-control/roles.md):
     * `compute.editor`: To manage the instance group.
     * `iam.serviceAccounts.user`: To link the service account to the group’s VM instances.
     * `functions.functionInvoker`: To call the Cloud Functions function.
  1. Click **Create**.

- CLI {#cli}

  1. Create a service account:

     ```bash
     yc iam service-account create --name vm-scale-scheduled-sa \
       --folder-name example-folder
     ```

     Result:

     ```yaml
     id: ajeab0cnib1p********
     folder_id: b0g12ga82bcv********
     created_at: "2022-03-15T09:44:35.989446Z"
     name: vm-scale-scheduled-sa
     ```

     For more information about the `yc iam service-account create` command, see the [CLI reference](../../../cli/cli-ref/iam/cli-ref/service-account/create.md).
  1. Assign these [roles](../../../iam/concepts/access-control/roles.md) to the service account:
     * `compute.editor`: To manage the instance group:

       ```bash
       yc resource-manager folder add-access-binding example-folder \
         --service-account-name vm-scale-scheduled-sa \
         --role compute.editor \
         --folder-name example-folder
       ```

     * `iam.serviceAccounts.user`: To link the service account to the group’s instances:

       ```bash
       yc resource-manager folder add-access-binding example-folder \
         --service-account-name vm-scale-scheduled-sa \
         --role iam.serviceAccounts.user \
         --folder-name example-folder
       ```

     * `functions.functionInvoker`: To call the Cloud Functions function:

       ```bash
       yc resource-manager folder add-access-binding example-folder \
         --service-account-name vm-scale-scheduled-sa \
         --role functions.functionInvoker \
         --folder-name example-folder
       ```

     For more information about the `yc resource-manager folder add-access-binding` command, see the [CLI reference](../../../cli/cli-ref/resource-manager/cli-ref/folder/add-access-binding.md).

- API {#api}

  1. Create a service account named `vm-scale-scheduled-sa`. Do it by using the [create](../../../iam/api-ref/ServiceAccount/create.md) REST API method for the [ServiceAccount](../../../iam/api-ref/ServiceAccount/index.md) resource or the [ServiceAccountService/Create](../../../iam/api-ref/grpc/ServiceAccount/create.md) gRPC API call.
  1. Assign the service account these [roles](../../../iam/concepts/access-control/roles.md) for the current folder:
     * `compute.admin`: To manage the instance group.
     * `iam.serviceAccounts.user`: To link the service account to the group’s VM instances.
     * `functions.functionInvoker`: To call the Cloud Functions function.

     Do it by using the [setAccessBindings](../../../resource-manager/api-ref/Folder/setAccessBindings.md) REST API method for the [Folder](../../../resource-manager/api-ref/Folder/index.md) resource or the [FolderService/SetAccessBindings](../../../resource-manager/api-ref/grpc/Folder/setAccessBindings.md) gRPC API call.

{% endlist %}

### Create a cloud network {#create-network}

The instance group will reside in the [Yandex Virtual Private Cloud](../../../vpc/index.md) [network](../../../vpc/concepts/network.md#network) and its [subnets](../../../vpc/concepts/network.md#subnet).

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Virtual Private Cloud**.
  1. At the top right, click **Create network**.
  1. In the **Name** field, specify `vm-scale-scheduled-network`.
  1. Select **Create subnets**.
  1. Click **Create network**.

- CLI {#cli}

  1. Create a network named `vm-scale-scheduled-network`:

     ```bash
     yc vpc network create --name vm-scale-scheduled-network \
       --folder-name example-folder
     ```

     Result:

     ```yaml
     id: enpabce123hd********
     folder_id: b0g12ga82bcv********
     created_at: "2022-03-15T09:55:50.004472Z"
     name: vm-scale-scheduled-network
     ```

     For more information about the `yc vpc network create` command, see the [CLI reference](../../../cli/cli-ref/vpc/cli-ref/network/create.md).
  1. Create a subnet named `vm-scale-scheduled-subnet-a` in the `ru-central1-a` [availability zone](../../../overview/concepts/geo-scope.md):

     ```bash
     yc vpc subnet create --name vm-scale-scheduled-subnet-a \
       --folder-name example-folder \
       --network-name vm-scale-scheduled-network --range 192.168.1.0/24 \
       --zone ru-central1-a
     ```

     Result:

     ```yaml
     id: e1lnabc23r1c********
     folder_id: b0g12ga82bcv********
     created_at: "2022-03-15T09:56:51.859345Z"
     name: vm-scale-scheduled-subnet-a
     network_id: enpabce123hd********
     zone_id: ru-central1-a
     v4_cidr_blocks:
     - 192.168.1.0/24
     ```

     For more information about the `yc vpc subnet create` command, see the [CLI reference](../../../cli/cli-ref/vpc/cli-ref/subnet/create.md).
  1. Create a subnet named `vm-scale-scheduled-network-b` in the `ru-central1-b` availability zone:

     ```bash
     yc vpc subnet create --name vm-scale-scheduled-subnet-b \
       --folder-name example-folder \
       --network-name vm-scale-scheduled-network --range 192.168.2.0/24 \
       --zone ru-central1-b
     ```

     Result:

     ```yaml
     id: b1csa2b3clid********
     folder_id: b0g12ga82bcv********
     created_at: "2022-03-15T09:57:48.934429Z"
     name: vm-scale-scheduled-subnet-b
     network_id: enpabce123hd********
     zone_id: ru-central1-b
     v4_cidr_blocks:
     - 192.168.2.0/24
     ```

- API {#api}

  1. Create a network named `vm-scale-scheduled-network` using the [create](../../../vpc/api-ref/Network/create.md) REST API method for the [Network](../../../vpc/api-ref/Network/index.md) resource or the [NetworkService/Create](../../../vpc/api-ref/grpc/Network/create.md) gRPC API call.
  1. Create subnets named `vm-scale-scheduled-subnet-a` in the `ru-central1-a` availability zone and `vm-scale-scheduled-subnet-b` in the `ru-central1-b` availability zone using the [create](../../../vpc/api-ref/Subnet/create.md) REST API method for the [Subnet](../../../vpc/api-ref/Subnet/index.md) resource or the [SubnetService/Create](../../../vpc/api-ref/grpc/Subnet/create.md) gRPC API call.

{% endlist %}

## Create an instance group {#create-ig}

We will create an instance group with manual scaling so that the Cloud Functions function can manage the group size.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
  1. At the top right, click **Create group of virtual machines**.
  1. Under **Basic parameters**:
     * In the **Name** field, specify `vm-scale-scheduled-ig`.
     * Select **Service account** `vm-scale-scheduled-sa`.
  1. Under **Allocation**, select `ru-central1-a` and `ru-central1-b` in the **Availability zone** field.
  1. Under **Instance template**, click **Define** and do the following in the window that opens:
     * Under **Boot disk image**, navigate to the **Boot disk image** tab and select [Ubuntu 20.04](https://yandex.cloud/en/marketplace/products/yc/ubuntu-20-04-lts).
     * Under **Computing resources**, specify this configuration:
       * **Platform**: `Intel Ice Lake`
       * **vCPU**: `2`
       * **Guaranteed vCPU performance**: `20%`
       * **RAM**: `2 GB`
     * Under **Network settings**:
       * In the **Network** field, select `vm-scale-scheduled-network`.
       * In the **Public address** field, select `No address`.
     * Under **Access**:
       * In the **Service account** field, select `vm-scale-scheduled-sa`.
       * In the **Login** field, enter the name of the user to create on the VM. You can enter any username of your choice.
       * In the **SSH key** field, paste the public SSH key contents. You can create a key pair by following [this guide](../../../compute/operations/vm-connect/ssh.md#creating-ssh-keys).
     * Click **Save**.
  1. Under **Changes during creation and updates**, specify this configuration:
     * **Add above target value**: `2` 
     * **Reduce below target value**: `2`
     * **Create simultaneously**: `2`
     * **Stop simultaneously**: `2`
  1. Under **Scaling**:
     * In the **Type** field, select `Fixed`.
     * Specify **Size** `2`.
  1. Click **Create**.

- CLI {#cli}

  1. Get the IDs of the resources you created at the previous steps:
     * `vm-scale-scheduled-sa` service account ID:

       ```bash
       yc iam service-account get vm-scale-scheduled-sa \
         --folder-name example-folder | grep "^id"
       ```

       Result:

       ```yaml
       id: ajeab0cnib1p********
       ```

       For more information about the `yc iam service-account get` command, see the [CLI reference](../../../cli/cli-ref/iam/cli-ref/service-account/get.md).
     * `vm-scale-scheduled-network` ID:

       ```bash
       yc vpc network get vm-scale-scheduled-network \
         --folder-name example-folder | grep "^id"
       ```

       Result:

       ```yaml
       id: enpabce123hd********
       ```

       For more information about the `yc vpc network get` command, see the [CLI reference](../../../cli/cli-ref/vpc/cli-ref/network/get.md).
     * `vm-scale-scheduled-subnet-a` ID:

       ```bash
       yc vpc subnet get vm-scale-scheduled-subnet-a \
         --folder-name example-folder | grep "^id"
       ```

       Result:

       ```yaml
       id: e1lnabc23r1c********
       ```

       For more information about the `yc vpc subnet get` command, see the [CLI reference](../../../cli/cli-ref/vpc/cli-ref/subnet/get.md).
     * `vm-scale-scheduled-subnet-b` ID:

       ```bash
       yc vpc subnet get vm-scale-scheduled-subnet-b \
         --folder-name example-folder | grep "^id"
       ```

       Result:

       ```yaml
       id: b1csa2b3clid********
       ```

       For more information about the `yc vpc subnet get` command, see the [CLI reference](../../../cli/cli-ref/vpc/cli-ref/subnet/get.md).
  1. Get the ID of the latest version of the [Ubuntu 20.04 LTS](https://yandex.cloud/en/marketplace/products/yc/ubuntu-20-04-lts) public image:

     ```bash
     yc compute image get-latest-from-family ubuntu-2004-lts \
       --folder-id standard-images | grep "^id"
     ```

     Result:

     ```yaml
     id: fd83n3uou8m0********
     ```

     For more information about the `yc compute image get-latest-from-family` command, see the [CLI reference](../../../cli/cli-ref/compute/cli-ref/image/get-latest-from-family.md).
  1. Insert these IDs in the `specification.yaml` file with the VM group spec:

     ```yaml
     name: vm-scale-scheduled-ig
     service_account_id: <service_ account_ID>
     allocation_policy:
        zones:
          - zone_id: ru-central1-a
          - zone_id: ru-central1-b
     instance_template:
       platform_id: standard-v3
       resources_spec:
         memory: 2G
         cores: 2
         core_fraction: 20
       boot_disk_spec:
         mode: READ_WRITE
         disk_spec:
           type_id: network-hdd
           size: 15G
           image_id: <ID_of_Ubuntu_20.04_LTS_latest_version>
       network_interface_specs:
        - network_id: <network_ID>
          subnet_ids:
            - <subnet_ID_in_ru-central1-a_zone>
            - <subnet_ID_in_ru-central1-b_zone>
          primary_v4_address_spec: {}
     scale_policy:
       fixed_scale:
         size: 2
     deploy_policy:
       max_unavailable: 2
       max_creating: 2
       max_expansion: 2
       max_deleting: 2
     ```

  1. Create an instance group named `vm-scale-scheduled-ig` based on `specification.yaml`:

     ```bash
     yc compute instance-group create --file specification.yaml \
       --folder-name example-folder
     ```

     Result:

     ```text
     done (2m18s)
     id: cl0kabcquk1g********
     folder_id: b0g12ga82bcv********
     ...
     service_account_id: ajeab0cnib1p********
     status: ACTIVE
     ```

- API {#api}

  1. Get the IDs of the resources you created in the previous steps:
     * `vm-scale-scheduled-sa` service account ID: Using the [get](../../../iam/api-ref/ServiceAccount/get.md) REST API method for the [ServiceAccount](../../../iam/api-ref/ServiceAccount/index.md) resource or the [ServiceAccountService/Get](../../../iam/api-ref/grpc/ServiceAccount/get.md) gRPC API call.
     * `vm-scale-scheduled-network` ID: Using the [get](../../../vpc/api-ref/Network/get.md) REST API method for the [Network](../../../vpc/api-ref/Network/index.md) resource or the [NetworkService/Get](../../../vpc/api-ref/grpc/Network/get.md) gRPC API call.
     * `vm-scale-scheduled-subnet-a` and `vm-scale-scheduled-subnet-b` IDs: Using the [get](../../../vpc/api-ref/Subnet/get.md) REST API method for the [Subnet](../../../vpc/api-ref/Subnet/index.md) resource or the [SubnetService/Get](../../../vpc/api-ref/grpc/Subnet/get.md) gRPC API call.
  1. Get the ID of the latest version of the public [Ubuntu 20.04](https://yandex.cloud/en/marketplace/products/yc/ubuntu-20-04-lts) image in the `standard-images` family using the [getLatestByFamily](../../../compute/api-ref/Image/getLatestByFamily.md) REST API method for the [Image](../../../compute/api-ref/Image/index.md) resource or the [ImageService/GetLatestByFamily](../../../compute/api-ref/grpc/Image/getLatestByFamily.md) gRPC API call.
  1. Insert these IDs in the `specification.yaml` file with the VM group spec:

     ```yaml
     name: vm-scale-scheduled-ig
     service_account_id: <service_ account_ID>
     allocation_policy:
        zones:
          - zone_id: ru-central1-a
          - zone_id: ru-central1-b
     instance_template:
       platform_id: standard-v3
       resources_spec:
         memory: 2G
         cores: 2
         core_fraction: 20
       boot_disk_spec:
         mode: READ_WRITE
         disk_spec:
           type_id: network-hdd
           size: 15G
           image_id: <ID_of_Ubuntu_20.04_LTS_latest_version>
       network_interface_specs:
        - network_id: <network_ID>
          subnet_ids:
            - <subnet_ID_in_ru-central1-a_zone>
            - <subnet_ID_in_ru-central1-b_zone>
          primary_v4_address_spec: {}
     scale_policy:
       fixed_scale:
         size: 2
     deploy_policy:
       max_unavailable: 2
       max_creating: 2
       max_expansion: 2
       max_deleting: 2
     ```

  1. Create an instance group named `vm-scale-scheduled-ig` based on `specification.yaml`. To do this, use the [createFromYaml](../../../compute/instancegroup/api-ref/InstanceGroup/createFromYaml.md) REST API method for the [InstanceGroup](../../../compute/instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/CreateFromYaml](../../../compute/instancegroup/api-ref/grpc/InstanceGroup/createFromYaml.md) gRPC API call.

{% endlist %}

## Create Cloud Functions resources {#create-sf-resources}

### Create a function {#create-function}

The function will contain the code with the Yandex Cloud CLI commands used to update the instance group.

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Cloud Functions**.
  1. At the top right, click **Create function**.
  1. In the **Name** field, specify `vm-scale-scheduled-function`.
  1. Click **Create**.
  1. Select the **Bash** runtime environment.
  1. Enable **Add files with code examples**.
  1. Click **Continue**.
  1. Under **Editor**, select the `handler.sh` file.
  1. Replace its contents with the code below:

     ```bash
     # Get ID and current size of the instance group
     IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json)
     IG_ID=$(jq -r ".id" <<< $IG_SPEC)
     IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC)
     
     # Calculate new size for the instance group
     if [ $IG_SIZE = $IG_BASE_SIZE ]; then
         IG_SIZE="$(($IG_BASE_SIZE + 1))"
     else
         IG_SIZE=$IG_BASE_SIZE
     fi
     
     # Update the instance group
     yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
     ```

  1. Under **Parameters**:
     * Set the **Timeout** field value to `60`.
     * In the **Service account** field, select `vm-scale-scheduled-sa`.
     * Under **Environment variables**, add these variables:
       * `IG_NAME` = `vm-scale-scheduled-ig`.
       * `IG_BASE_SIZE` = `2`.
       * `FOLDER_ID` = `<your_folder_ID>`. You can get the ID by following [this guide](../../../resource-manager/operations/folder/get-id.md).
  1. In the top-right corner, click **Save changes**.

- CLI {#cli}

  1. Create a file named `handler.sh` with this code:

     ```bash
     # Get ID and current size of the instance group
     IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json)
     IG_ID=$(jq -r ".id" <<< $IG_SPEC)
     IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC)
     
     # Calculate new size for the instance group
     if [ $IG_SIZE = $IG_BASE_SIZE ]; then
         IG_SIZE="$(($IG_BASE_SIZE + 1))"
     else
         IG_SIZE=$IG_BASE_SIZE
     fi
     
     # Update the instance group
     yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
     ```

  1. Create a function:
 
     ```bash
     yc serverless function create vm-scale-scheduled-function \
       --folder-name example-folder
     ```

     Result:

     ```text
     done (1s)
     id: d4e7d67ikvmq********
     folder_id: b1g9hv2loamq********
     ...
     log_group_id: ckgij6l0845h********
     http_invoke_url: https://functions.yandexcloud.net/d4e7d67ikvmq********
     status: ACTIVE
     ```

  1. Create a function version:

     ```bash
     yc serverless function version create --folder-name example-folder \
       --function-name vm-scale-scheduled-function --runtime bash \
       --source-path ./handler.sh --entrypoint "handler.sh" \
       --execution-timeout 60s \
       --service-account-id <service_account_ID> \
       --environment \
         IG_NAME=vm-scale-scheduled-ig,IG_BASE_SIZE=2,FOLDER_ID=<folder_ID>
     ```

     Where:
     * `--service-account-id`: `vm-scale-schedule-sa` ID. To get the ID, follow the [Create a VM group](#create-ig) step on the **CLI** tab.
     * `FOLDER_ID` in `--environment`. You can get the ID by following [this guide](../../../resource-manager/operations/folder/get-id.md).

     Result:

     ```text
     done (1s)
     id: d4efmv9n3qf1********
     function_id: d4e7d67ikvmq********
     ...
       FOLDER_ID: b1g9hv2loamq********
       IG_BASE_SIZE: "2"
       IG_NAME: vm-scale-scheduled-ig
     ```

- API {#api}

  1. Create a function named `vm-scale-scheduled-function` using the [create](../../../functions/functions/api-ref/Function/create.md) REST API method for the [Function](../../../functions/functions/api-ref/Function/index.md) resource or the [FunctionService/Create](../../../functions/functions/api-ref/grpc/Function/create.md) gRPC API call. From the output, get the ID of the function you created.
  1. Create a function version using the [createVersion](../../../functions/functions/api-ref/Function/createVersion.md) REST API method for the [Function](../../../functions/functions/api-ref/Function/index.md) resource or the [FunctionService/CreateVersion](../../../functions/functions/api-ref/grpc/Function/createVersion.md) gRPC API call. The function version should have this code:

     ```bash
     # Get ID and current size of the instance group
     IG_SPEC=$(yc compute instance-group get --name $IG_NAME --folder-id $FOLDER_ID --format json)
     IG_ID=$(jq -r ".id" <<< $IG_SPEC)
     IG_SIZE=$(jq -r ".scale_policy.fixed_scale.size" <<< $IG_SPEC)
     
     # Calculate new size for the instance group
     if [ $IG_SIZE = $IG_BASE_SIZE ]; then
         IG_SIZE="$(($IG_BASE_SIZE + 1))"
     else
         IG_SIZE=$IG_BASE_SIZE
     fi
     
     # Update the instance group
     yc compute instance-group update --id $IG_ID --scale-policy-fixed-scale-size $IG_SIZE
     ```

{% endlist %}

### Create a trigger {#create-trigger}

A [trigger](../../../functions/concepts/trigger/index.md) sets conditions for running a function. For scheduled function calls, use a [timer trigger](../../../functions/concepts/trigger/timer.md).

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Cloud Functions**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/gear-play.svg) **Triggers**.
  1. At the top right, click **Create trigger**.
  1. Under **Basic settings**:
     * In the **Name** field, specify `vm-scale-scheduled-trigger`.
     * In the **Type** field, select `Timer`.
     * In the **Launched resource** field, select `Function`.
  1. Under **Timer settings**, in the **Cron expression** field, specify `*/2 * * * ? *`. The trigger will fire every two minutes, e.g., at 09:58, 10:00, 10:02, 10:04, etc.
  1. Under **Function settings**:
     * In the **Function** field, specify `vm-scale-scheduled-function`.
     * In the **Function version tag** field, select `$latest`.
     * Select **Service account** `vm-scale-scheduled-sa`.
  1. Under **Dead Letter Queue settings**, reset the **Service account** (`Not selected`) field.
  1. Click **Create trigger**.

- CLI {#cli}

  Run this command:

  ```bash
  yc serverless trigger create timer --folder-name example-folder \
    --name vm-scale-scheduled-trigger \
    --cron-expression "*/2 * * * ? *" \
    --invoke-function-name vm-scale-scheduled-function \
    --invoke-function-tag '$latest' \
    --invoke-function-service-account-name vm-scale-scheduled-sa
  ```

  Result:

  ```yaml
  id: a1s22pb0v5i4********
  folder_id: b1g9hv2loamq********
  created_at: "2022-04-06T14:56:54.253709098Z"
  ...
        function_tag: $latest
        service_account_id: aje9s4pud13h********
  status: ACTIVE
  ```

- API {#api}

  Create a `timer` trigger with the `*/2 * * * ? *` cron expression by using the [create](../../../functions/triggers/api-ref/Trigger/create.md) REST API method for the [Trigger](../../../functions/triggers/api-ref/Trigger/index.md) resource or the [TriggerService/Create](../../../functions/triggers/api-ref/grpc/Trigger/create.md) gRPC API call. This trigger will be linked to `vm-scale-scheduled-function` of the `$latest` version and the `vm-scale-scheduled-sa` service account.

{% endlist %}

## Test instance group scaling {#test-scale}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select `example-folder`.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/layers-3-diagonal.svg) **Instance groups**.
  1. Select `vm-scale-scheduled-ig`.
  1. Under **Virtual machines**, make sure the number of instances changes every two minutes: increases from 2 to 3, then decreases from 3 to 2, etc. You can also check if the instance group has been updated by opening the ![image](../../../_assets/console-icons/list-check.svg) **Operations** tab.

- CLI {#cli}

  Run the following command several times:

  ```bash
  yc compute instance-group get vm-scale-scheduled-ig \
    --folder-name example-folder
  ```

  Result:

  ```yaml
  id: cl1l0ljqbmkp********
  folder_id: b1g9hv2loamq********
  created_at: "2022-03-28T13:24:20.693Z"
  ...
  managed_instances_state:
    target_size: "2"
    running_actual_count: "2"
  ...
  ```

  The value of the `target_size` field for the group should change from `2` to `3` and back.

- API {#api}

  Get information about the `vm-scale-scheduled-ig` instance group multiple times using the [get](../../../compute/instancegroup/api-ref/InstanceGroup/get.md) REST API method for the [InstanceGroup](../../../compute/instancegroup/api-ref/InstanceGroup/index.md) resource or the [InstanceGroupService/Get](../../../compute/instancegroup/api-ref/grpc/InstanceGroup/get.md) gRPC API call. The value of the `target_size` field for the group should change from `2` to `3` and back.

{% endlist %}

## How to delete the resources you created {#clear-out}

To stop paying for the resources you created:
1. [Delete the trigger](../../../functions/operations/trigger/trigger-delete.md).
1. [Delete](../../../functions/operations/function/function-delete.md) the function.
1. [Delete](../../../compute/operations/instance-groups/delete.md) the instance group.

#### Useful links {#see-also}

* [Scheduled instance group scaling with Terraform](terraform.md).