All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ESS-AdjustScalingGroupInstanceCount

Last Updated:Jun 22, 2026

Adjust the number of instances in a scaling group or the number of nodes in an ACK cluster node pool by creating and executing a scaling rule.

Template name

ACS-ESS-AdjustScalingGroupInstanceCount

Execute Now

Template description

Creates and executes a scaling rule to adjust the number of instances in a scaling group. Note:

  • If the scaling group has a configured expected number of instances and the actual count differs, Auto Scaling automatically adds or removes instances to match the expected number. After you execute the template, check the scaling result in the Auto Scaling console.

  • After a scale-in, the number of nodes in an ACK cluster cannot be smaller than the minimum number required by the components. Otherwise, the IncorrectCapacity error code is returned.

  • Before you execute the template, make sure that your account balance covers the cost of purchasing new instances. Otherwise, the InvalidAccountStatus.NotEnoughBalance error code is returned.

  • To scale out a scaling group deployed across multiple zones, set the AdjustmentCount parameter to: Number of instances to add per zone × Number of zones.

  • ECS instances added after a scale-out are billed on a pay-as-you-go basis. You can change the billing method to subscription as needed. For more information, see Change the billing method from pay-as-you-go to subscription.

  • Two scale-in methods are available: remove a specific number of ECS instances by configuring the AdjustmentCount parameter, or remove specific ECS instances by setting AdjustmentCount to 0 and selecting the instances to remove.

  • The number of instances removed during a scale-in cannot be less than the number initially created for the scaling group.

Adjusts the number of nodes in an ACK cluster node pool. For more information, see Create and manage node pools. Note:

  • Read the linked document and grant permissions to the AliyunOOSLifecycleHook4CSRole role.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

resourceType

The resource type to adjust.

String

No

ESS

regionId

The region ID of the scaling group.

String

No

{{ ACS::RegionId }}

scalingGroupId

The ID of the scaling group.

String

No

""

adjustmentType

The scaling method.

String

No

ScaleOut

adjustmentCount

The number of ECS instances to add or remove in the scaling group.

Number

No

0

instancesToBeRemoved

The ECS instances to remove from the scaling group.

Json

No

{'Type': 'ResourceIds', 'ResourceIds': [], 'RegionId': '{{ ACS::RegionId }}'}

clusterId

The ID of the ACK cluster.

String

No

""

nodepoolId

The ID of the node pool.

String

No

""

desiredSize

The expected number of nodes.

Number

No

0

OOSAssumeRole

The RAM role assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

Parameter

Description

Type

adjustDetail

String

lifecycleHookOOSExecutionResult

String

Policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ess:CreateScalingRule",
                "ess:DeleteScalingRule",
                "ess:DescribeScalingActivities",
                "ess:DescribeScalingActivityDetail",
                "ess:ExecuteScalingRule",
                "ess:RemoveInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:ListExecutions"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "cs:DescribeClusterNodePoolDetail",
                "cs:ModifyClusterNodePool"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

ACS-ESS-AdjustScalingGroupInstanceCount

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: <p class="p">Adjust the number of instances in a scaling group by creating and executing scaling group rules. Description:</p>
    <ul class="ul">
    <li class="li">If the scaling group has been configured with the desired number of instances, when the number of instances in the scaling group is not equal to the expected number of instances, the auto scaling service will automatically scale to ensure that the number of instances in the scaling group is always maintained After the execution is complete, please go to the ESS console to view the adjustment results. </li>
    <li class="li">The number of cluster nodes after scaling down the nodes cannot be less than the minimum node requirements of the component, otherwise the scaling operation may return an error of code:IncorrectCapacity. </li>
    <li class="li">Please ensure that your account balance is greater than the cost of the newly purchased instance, otherwise an error of code:InvalidAccountStatus.NotEnoughBalance will be returned. </li>
    <li class="li">If it is multi-zone, please expand the multiple of the number of zones. </li>
    <li class="li">The payment method for the expanded ECS is pay-as-you-go. If necessary, customers need to Manual subcontracting yearly and monthly. </a></li>
    <li class="li"> There are two ways to scale down: scale down the specified number of ECS instances (<b>the number of ECS instance adjustments in the scaling group</b> is not 0), remove the specified ECS instances from the scaling group (<b>The number of ECS instance adjustments in the scaling group</b> is 0 and the ECS instances to be removed is selected)</li>
    <li class="li">The scaling cannot be less than the number initially opened in the scaling group. </li>
    </ul>
    <p class="p">Adjust the number of instances in a scaling group by creating and executing scaling group rules. Description:</p>
    <ul class="ul">
    <li class="li">Adjust ACK cluster node pool<a href='https://www.alibabacloud.com/help/en/ack/ack-edge/user-guide/create-a-node-pool?spm=a3c0i.23458820.2359477120.9.57186e9b4Ewe21'>Expected number of nodes</a>, please read the linked document carefully and authorize the role AliyunOOSLifecycleHook4CSRole. </li>
    </ul>
  name-en: Elastic Scaling
  categories:
    - elastic_manage
    - application_manage
    - computenest
Parameters:
  resourceType:
    Type: String
    Label:
      en: ResourceType
    AllowedValues:
      - ACK
      - ESS
    Default: ESS
  regionId:
    Type: String
    Label:
      en: RegionId
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  scalingGroupId:
    Type: String
    Label:
      en: ScalingGroupId
    Default: ''
    AssociationProperty: ALIYUN::ESS::AutoScalingGroup::AutoScalingGroupId
    AssociationPropertyMetadata:
      RegionId: regionId
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
  adjustmentType:
    Type: String
    Label:
      en: AdjustmentType
    AssociationPropertyMetadata:
      LocaleKey: ESSGroupAdjustmentType
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
    AllowedValues:
      - ScaleOut
      - ScaleIn
      - TotalCapacity
    Default: ScaleOut
  adjustmentCount:
    Type: Number
    Label:
      en: AdjustmentCount
    MinValue: 0
    MaxValue: 100
    Default: 0
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ESS
  instancesToBeRemoved:
    Type: Json
    Label:
      en: RemovedInstances
    Default:
      Type: ResourceIds
      ResourceIds: []
      RegionId: '{{ ACS::RegionId }}'
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
      Visible:
        Condition:
          Fn::And:
            - Fn::Equals:
                - '${resourceType}'
                - ESS
            - Fn::Equals:
                - '${adjustmentType}'
                - ScaleIn
            - Fn::Equals:
                - '${adjustmentCount}'
                - 0
  clusterId:
    Label:
      en: ClusterId
    Type: String
    Default: ''
    AssociationProperty: ALIYUN::CS::Cluster::ClusterId
    AssociationPropertyMetadata:
      RegionId: ${regionId}
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  nodepoolId:
    Label:
      en: NodepoolId
    Type: String
    Default: ''
    AssociationProperty: ALIYUN::CS::Cluster::ClusterNodePool
    AssociationPropertyMetadata:
      RegionId: ${regionId}
      ClusterId: ${clusterId}
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  desiredSize:
    Label:
      en: DesiredSize
    Type: Number
    MinValue: 0
    MaxValue: 100
    Default: 0
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Equals:
            - '${resourceType}'
            - ACK
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: chooseNextTaskByResourceType
    Action: 'ACS::Choice'
    Description:
      en: Choose next task by resource type
    Properties:
      DefaultTask: whetherToRemoveInstancesFromScalingGroup
      Choices:
        - When:
            Fn::Equals:
              - 'ACK'
              - '{{ resourceType }}'
          NextTask: getNodePoolDetail
  - Name: whetherToRemoveInstancesFromScalingGroup
    Action: 'ACS::Choice'
    Description:
      en: Choose next task by adjustment type
    Properties:
      DefaultTask: createScalingRule
      Choices:
        - When:
            Fn::And:
              - Fn::Equals:
                  - '{{adjustmentType}}'
                  - ScaleIn
              - Fn::Equals:
                  - '{{adjustmentCount}}'
                  - 0
          NextTask: getInstanceToBeRemoved
  - Name: getInstanceToBeRemoved
    Description:
      en: Get the ECS instance to be removed
    Action: ACS::SelectTargets
    Properties:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: '{{ regionId }}'
      Filters:
        - '{{ instancesToBeRemoved }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: Instances.Instance[].InstanceId
  - Name: removeInstances
    Action: 'ACS::ExecuteAPI'
    OnSuccess: waitScalingActivityComplete
    When:
      Fn::Not:
        Fn::Equals:
          - '{{ getInstanceToBeRemoved.instanceIds }}'
          - []
    Description:
      en: Remove instances from scaling group
    Properties:
      Service: ESS
      API: RemoveInstances
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingGroupId: '{{ scalingGroupId }}'
        InstanceIds: '{{ getInstanceToBeRemoved.instanceIds }}'
    Outputs:
      scalingActivityId:
        Type: String
        ValueSelector: .ScalingActivityId
  - Name: createScalingRule
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Create a ScalingRule
    Properties:
      Service: ESS
      API: CreateScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingGroupId: '{{ scalingGroupId }}'
        ScalingRuleName: '{{ ACS::ExecutionId }}'
        AdjustmentType:
          Fn::If:
            - Fn::Equals:
                - 'TotalCapacity'
                - '{{ adjustmentType }}'
            - TotalCapacity
            - QuantityChangeInCapacity
        AdjustmentValue:
          Fn::If:
            - Fn::Equals:
                - ScaleIn
                - '{{ adjustmentType }}'
            - '-{{ adjustmentCount }}'
            - '{{ adjustmentCount }}'
    Outputs:
      scalingRuleAri:
        Type: String
        ValueSelector: ScalingRuleAri
      scalingRuleId:
        Type: String
        ValueSelector: ScalingRuleId
  - Name: executeScalingRule
    Description:
      en: Execute the ScalingRule
    OnError: deleteScalingRule
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: ExecuteScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingRuleAri: '{{ createScalingRule.scalingRuleAri }}'
    Outputs:
      scalingActivityId:
        Type: String
        ValueSelector: ScalingActivityId
  - Name: waitScalingActivityComplete
    Description:
      en: Poll scaling activity execution until success or failure
    OnError: deleteScalingRule
    Retries: 30
    Action: 'ACS::WaitFor'
    Properties:
      Service: ESS
      API: DescribeScalingActivities
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingActivityId1:
          Fn::If:
            - Fn::And:
                - Fn::Equals:
                    - '{{adjustmentType}}'
                    - ScaleIn
                - Fn::Equals:
                    - '{{adjustmentCount}}'
                    - 0
            - '{{ removeInstances.scalingActivityId }}'
            - '{{ executeScalingRule.scalingActivityId }}'
      DesiredValues:
        - Successful
      StopRetryValues:
        - Failed
        - Rejected
        - Warning
      PropertySelector: 'ScalingActivities.ScalingActivity[0].StatusCode'
  - Name: deleteScalingRule
    When:
      Fn::Not:
        Fn::And:
          - Fn::Equals:
              - '{{adjustmentType}}'
              - ScaleIn
          - Fn::Equals:
              - '{{adjustmentCount}}'
              - 0
    Description:
      en: Delete ScalingRule
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: DeleteScalingRule
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingRuleId: '{{ createScalingRule.scalingRuleId }}'
  - Name: describeScalingActivityDetail
    Description:
      en: Describe scaling activity detail
    Action: 'ACS::ExecuteApi'
    Properties:
      Service: ESS
      API: DescribeScalingActivityDetail
      Parameters:
        RegionId: '{{ regionId }}'
        ScalingActivityId:
          Fn::If:
            - Fn::And:
                - Fn::Equals:
                    - '{{adjustmentType}}'
                    - ScaleIn
                - Fn::Equals:
                    - '{{adjustmentCount}}'
                    - 0
            - '{{ removeInstances.scalingActivityId }}'
            - '{{ executeScalingRule.scalingActivityId }}'
    Outputs:
      detail:
        Type: String
        ValueSelector: .Detail
  - Name: getOOSExecutionOutput
    Action: 'ACS::ExecuteAPI'
    OnSuccess: ACS::END
    Description:
      en: Get the lifecycle hook OOS execution output
    Properties:
      Service: OOS
      API: ListExecutions
      Parameters:
        RegionId: '{{ regionId }}'
        Tags:
          ESS:ScalingActivityId:
            Fn::If:
              - Fn::And:
                  - Fn::Equals:
                      - '{{adjustmentType}}'
                      - ScaleIn
                  - Fn::Equals:
                      - '{{adjustmentCount}}'
                      - 0
              - '{{ removeInstances.scalingActivityId }}'
              - '{{ executeScalingRule.scalingActivityId }}'
    Outputs:
      lifecycleHookOOSExecutionResult:
        Type: String
        ValueSelector: 'Executions[].Outputs'
  - Name: getNodePoolDetail
    Action: ACS::WaitFor
    Description:
      en: Get cluster node pool info
    Retries: 20
    Properties:
      Service: CS
      API: DescribeClusterNodePoolDetail
      Method: GET
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      Parameters: {}
      DesiredValues:
        - active
      PropertySelector: .status.state
    Outputs:
      nodePoolInfo:
        Type: Json
        ValueSelector: .
  - Name: modifyClusterNodePool
    Action: ACS::ExecuteAPI
    Description:
      en: Modify cluster node pool configuration
    Properties:
      Service: CS
      API: ModifyClusterNodePool
      Method: PUT
      Headers:
        Content-Type: application/json
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      Body:
        Fn::Jq:
          - First
          - '.+({"scaling_group": (.scaling_group + {"desired_size": {{desiredSize}}})}) | del(.scaling_group.login_password)'
          - '{{ getNodePoolDetail.nodePoolInfo }}'
  - Name: untilClusterNodePoolReady
    Action: ACS::WaitFor
    Description:
      en: Wait for the cluster node pool configuration to complete
    Retries: 20
    Properties:
      Service: CS
      API: DescribeClusterNodePoolDetail
      Method: GET
      Parameters: {}
      URI: /clusters/{{clusterId}}/nodepools/{{nodepoolId}}
      DesiredValues:
        - active
      PropertySelector: .status.state
Outputs:
  adjustDetail:
    Type: String
    Value: '{{ describeScalingActivityDetail.detail }}'
  lifecycleHookOOSExecutionResult:
    Type: String
    Value: '{{ getOOSExecutionOutput.lifecycleHookOOSExecutionResult }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - regionId
          - resourceType
          - scalingGroupId
          - adjustmentType
          - adjustmentCount
          - instancesToBeRemoved
          - clusterId
          - nodepoolId
          - desiredSize
        Label:
          default:
            en: Scaling Rule Configure Parameters
      - Parameters:
          - OOSAssumeRole
        Label:
          default:
            en: Control Options