All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ECS-BulkyDeleteInstances

Last Updated:Jun 22, 2026

Template name

ACS-ECS-BulkyDeleteInstances: Bulk delete ECS instances

Execute Now

Description

Bulk-deletes pay-as-you-go ECS instances for resource release and cost optimization. Provide the region ID (regionId) and the target instances (targets). Optionally, set force to forcibly delete running instances. After execution, the template returns a list of deleted instance IDs for verification.

Template type

Automation

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Type

Required

Default

Constraints

targets

The target ECS instances.

Json

Yes

regionId

The region of the ECS instances.

String

No

{{ ACS::RegionId }}

force

Whether to forcibly delete running instances.

Boolean

No

False

rateControl

Rate control settings for the task.

Json

No

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

OOSAssumeRole

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

String

No

""

Output parameters

DeletedInstanceIds: A list of instance IDs that were deleted.

Required permissions

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

Details

ACS-ECS-BulkyDeleteInstances details

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: 'Bulk-deletes pay-as-you-go ECS instances to simplify resource release and cost optimization. You must provide the region ID and the target instances. You can also choose to forcibly delete running instances. After execution, the template returns a list of deleted instance IDs for verification.'
  zh-cn: 批量删除ECS按量付费实例,适用于需要同时管理和删除多台按量付费ECS实例的场景,例如资源释放和成本优化。在配置过程中,用户需要提供以下必填参数信息,地域ID(regionId):用于指定需要删除实例的地域,目标实例(targets):用于定义具体需要操作的ECS实例。用户还可以选择是否强制删除正在运行的实例(force)。模板在执行后会返回删除的实例ID列表,方便用户验证实例删除的状态。
  name-en: Bulk Delete ECS Instances
  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 specified 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 the specified ECS instance.
    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