All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-BulkyDeleteInstances

Last Updated:Dec 23, 2025

Template name

ACS-ECS-BulkyDeleteInstances: Batch delete ECS instances

Execute Now

Template description

Deletes multiple pay-as-you-go Elastic Compute Service (ECS) instances in a batch. This template is useful for scenarios that require managing and deleting multiple pay-as-you-go ECS instances, such as for resource release and cost optimization. During configuration, provide the following required parameters: Region ID (regionId) to specify the region of the instances to delete, and Target Instances (targets) to specify the ECS instances to delete. You can also choose whether to force delete running instances (force). After execution, the template returns a list of the deleted instance IDs. This helps you verify the deletion status of the instances.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default value

Limit

targets

Target instance

Json

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

force

Specifies whether to forcibly stop and release running ECS instances.

Boolean

No

False

rateControl

Concurrent task execution rate

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

OOSAssumeRole

The Resource Access Management (RAM) role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

None

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DeleteInstance",
                "ecs:DescribeInstances"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "oos:GetApplicationGroup"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

Details

For more information, see ACS-ECS-BulkyDeleteInstances.yml at GitHub.

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: 'Deletes multiple pay-as-you-go ECS instances in a batch. This template is useful for scenarios that require managing and deleting multiple pay-as-you-go ECS instances at the same time, such as for resource release and cost optimization. During configuration, provide the following required parameters: Region ID (regionId) to specify the region of the instances to delete, and Target Instances (targets) to define the specific ECS instances to operate on. You can also choose whether to force delete running instances (force). After execution, the template returns a list of the deleted instance IDs. This helps you verify the deletion status of the instances.'
  zh-cn: 批量删除ECS按量付费实例,适用于需要同时管理和删除多台按量付费ECS实例的场景,例如资源释放和成本优化。在配置过程中,用户需要提供以下必填参数信息,地域ID(regionId): 用于指定需要删除实例的地域,目标实例(targets): 用于定义具体需要操作的ECS实例。用户还可以选择是否强制删除正在运行的实例(force)。模板在执行后会返回删除的实例ID列表,方便用户验证实例删除的状态。
  name-en: ACS-ECS-BulkyDeleteInstances
  name-zh-cn: 批量删除ECS实例
  categories:
    - instance_manage
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地域ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  targets:
    Type: Json
    Label:
      en: TargetInstance
      zh-cn: 目标实例
    AssociationProperty: Targets
    AssociationPropertyMetadata:
      ResourceType: ALIYUN::ECS::Instance
      RegionId: regionId
  force:
    Label:
      en: Force
      zh-cn: 是否强制释放正在运行的实例
    Type: Boolean
    Default: false
  rateControl:
    Label:
      en: RateControl
      zh-cn: 任务执行的并发比率
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
- Name: getInstance
  Description:
    en: Gets the ECS instances
    zh-cn: 获取ECS实例
  Action: ACS::SelectTargets
  Properties:
    ResourceType: ALIYUN::ECS::Instance
    RegionId: '{{ regionId }}'
    Filters:
      - '{{ targets }}'
  Outputs:
    instanceIds:
      Type: List
      ValueSelector: Instances.Instance[].InstanceId
- Name: deleteInstance
  Action: ACS::ExecuteAPI
  Description:
    en: Deletes an ECS instance by its ID
    zh-cn: 通过指定实例ID删除实例
  Properties:
    Service: ECS
    API: DeleteInstance
    Parameters:
      RegionId: '{{ regionId }}'
      InstanceId: '{{ ACS::TaskLoopItem }}'
      Force: '{{ force }}'
  Loop:
    RateControl: '{{ rateControl }}'
    Items: '{{ getInstance.instanceIds }}'
Metadata:
  ALIYUN::OOS::Interface:
    ParameterGroups:
      - Parameters:
          - force
        Label:
          default:
            zh-cn: 配置参数
            en: Configure Parameters
      - Parameters:
          - regionId
          - targets
        Label:
          default:
            zh-cn: 选择实例
            en: Select Instances
      - Parameters:
          - rateControl
          - OOSAssumeRole
        Label:
          default:
            zh-cn: 高级选项
            en: Advanced Options