Release ECS instances in bulk

更新时间:
复制 MD 格式

OOS provides public templates to release multiple ECS instances in bulk. Specify instance IDs to automate the process.

Prerequisites

You can release only Pay-as-you-go or subscription ECS instances.

Procedure

  1. Log on to the OOS console.

  2. In the left-side navigation pane, click Public Templates.

  3. Search for a template that matches your billing method, such as ACS-ECS-BulkyDeleteInstances for pay-as-you-go instances, and click Create Execution.

    ACS-ECS-BulkyDeleteInstances1

  4. Click Next: Set Parameters.

    image

  5. Configure the following parameters on the Set Parameters page.

    image

    Parameter

    Description

    Example

    targets

    Tags or instance IDs of the ECS instances to release.

    test:oos / i-bp10jvphtux8ad******

    force

    Whether to forcibly release a running instance.

    true/false

    rateControl

    Execution rate control method.

    concurrency control

    concurrency

    10

    error threshold

    10

    Permissions

    Optional.

    • Use Existing Permissions of Current Account (Default): Uses your current account permissions. Ensure your account can call all required ECS API operations.

    • Specify RAM Role: OOS assumes the specified RAM role to perform the task.

    Use Existing Permissions of Current Account

  6. Click Next: Review, confirm your settings, and click Create.

    image

  7. On the Task Execution Management page, check your execution. A state of Running indicates that the instances are being released.

  8. When the execution state changes to Succeeded, all specified instances are released.

  9. Verify that the instances are released. 2

Public templates

  • Bulk release pay-as-you-go instances (ACS-ECS-BulkyDeleteInstances)

FormatVersion: OOS-2019-06-01
Description:
  en: Deletes multiple pay-as-you-go ECS instances.
  zh-cn: 批量删除ECS按量付费实例。
  name-en: ACS-ECS-BulkyDeleteInstances
  name-zh-cn: 批量删除ECS实例
  categories:
    - instance_manage
Parameters:
  targets:
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
  force:
    Description:
      en: Specifies whether to forcibly release a running instance.
      zh-cn: 是否强制释放正在运行的实例。
    Type: Boolean
    Default: false
  rateControl:
    Description:
      en: Configures the rate control for the task.
      zh-cn: 任务执行的并发比率。
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Description:
      en: The RAM role that OOS assumes to perform the task.
      zh-cn: OOS扮演的RAM角色。
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstance
    Description:
      en: Gets the specified ECS instances.
      zh-cn: 获取ECS实例。
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: deleteInstance
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Deletes the ECS instance with the specified instance ID.
      zh-cn: 通过指定实例ID删除实例。
    Properties:
      Service: ECS
      API: DeleteInstance
      Parameters:
        InstanceId: '{{ ACS::TaskLoopItem }}'
        Force: '{{ force }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'            

This template:

  1. Gets target instances by ID or tag.

  2. Releases the instances in bulk.

  • Bulk release subscription instances (ACS-ECS-BulkyDeletePrepaidInstances)

FormatVersion: OOS-2019-06-01
Description:
  en: >-
    Deletes multiple subscription instances. The instances must be in the
    Stopped state.
  zh-cn: 批量删除ECS预付费实例。指定的ECS实例必须处于已停止状态。
  name-en: ACS-ECS-BulkyDeletePrepaidInstances
  name-zh-cn: 批量删除ECS预付费实例
  categories:
    - instance_manage
Parameters:
  targets:
    Type: Json
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: 'ALIYUN::ECS::Instance'
  rateControl:
    Description:
      en: Configures the rate control for the task.
      zh-cn: 任务执行的并发比率。
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Description:
      en: The RAM role that OOS assumes to perform the task.
      zh-cn: OOS扮演的RAM角色。
    Type: String
    Default: OOSServiceRole
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: getInstance
    Description:
      en: Gets the specified ECS instances.
      zh-cn: 获取ECS实例。
    Action: 'ACS::SelectTargets'
    Properties:
      ResourceType: 'ALIYUN::ECS::Instance'
      Filters:
        - '{{ targets }}'
    Outputs:
      instanceIds:
        Type: List
        ValueSelector: 'Instances.Instance[].InstanceId'
  - Name: modifyInstanceChargeType
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Changes the billing method of the subscription instances to pay-as-you-go.
      zh-cn: 修改预付费实例付费方式为按量付费。
    Properties:
      Service: ECS
      API: ModifyInstanceChargeType
      Parameters:
        InstanceIds: '{{ getInstance.instanceIds }}'
        InstanceChargeType: PostPaid
  - Name: deleteInstance
    Action: 'ACS::ECS::DeleteInstance'
    Description:
      en: Deletes the ECS instance by instance ID.
      zh-cn: 通过实例ID删除实例。
    Properties:
      instanceId: '{{ ACS::TaskLoopItem }}'
    Loop:
      RateControl: '{{ rateControl }}'
      Items: '{{ getInstance.instanceIds }}'

This template:

  1. Gets target instances by ID or tag.

  2. Converts subscription instances to pay-as-you-go.

  3. Releases the instances in bulk.