全部产品
Search
文档中心

资源管理:CreateAutoGroupingRule - 创建自动转组规则

更新时间:Aug 27, 2026

调用CreateAutoGroupingRule创建自动转组规则。支持自定义转组规则和关联资源跟随转组规则两类。

接口说明

自定义转组规则最多创建 10 个,每个自定义转组规则支持最多 10 条规则内容。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

调试

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。

  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。

  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:

    • 对于必选的资源类型,用前面加 * 表示。

    • 对于不支持资源级授权的操作,用全部资源表示。

  • 条件关键字:是指云产品自身定义的条件关键字。

  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。

操作

访问级别

资源类型

条件关键字

关联操作

resourcemanager:CreateAutoGroupingRule

create

*全部资源

*

请求语法

POST  HTTP/1.1

请求参数

名称

类型

必填

描述

示例值

RuleName

string

规则名称。

A项目线上资源自动转组规则

RuleDesc

string

规则描述。

带有标签 {"env": "online"} 和 {"project": "A"} 的资源转移到资源组 rg-aek2********qcy

RuleType

string

规则类型。取值:

  • custom_condition:自定义转组规则。

  • associated_transfer:关联资源跟随转组规则。

custom_condition

RuleContents

array<object>

规则内容列表。

object

规则内容。

AutoGroupingScopeCondition

string

自动转组范围条件,用于指定需要自动转组的资源范围。

{"children":[{"desired":"{\"env\":\"online\", \"project\":\"A\"}","featurePath":"$.tags","featureSource":"RESOURCE","operator":"TagMatchAll"}],"operator":"and"}

TargetResourceGroupCondition

string

目标资源组条件,用于指定自动分组的目标资源组。

{"children":[{"desired":"rg-aek2********qcy","featurePath":"$.resourceGroupId","featureSource":"RESOURCE","operator":"StringEquals"}],"operator":"and"}

ResourceGroupIdsScope

string

资源组 ID 范围,多个资源组 ID 用半角逗号(,)分隔。

rg-aekz******4b5ea,rg-aek2******fxykq

ExcludeResourceGroupIdsScope

string

资源组 ID 排除范围,多个资源组 ID 用半角逗号(,)分隔。

rg-aekz******zj2oi,rg-aekz******r62ua

RegionIdsScope

string

地域 ID 范围,多个地域 ID 用半角逗号(,)分隔。

cn-hangzhou,cn-shanghai

ExcludeRegionIdsScope

string

地域 ID 排除范围,多个地域 ID 用半角逗号(,)分隔。

cn-beijing,cn-guangzhou

ResourceIdsScope

string

资源 ID 范围,多个资源 ID 用半角逗号(,)分隔。

i-2zee******ym49kfmwis,vpc-5ts6******fnw493g849a

ExcludeResourceIdsScope

string

资源 ID 排除范围,多个资源 ID 用半角逗号(,)分隔。

pc-uf6p******4h784y,rmq-cn-******ny0y

ResourceTypesScope

string

资源类型范围,多个资源类型用半角逗号(,)分隔。

rds.dbinstance,oss.bucket

ExcludeResourceTypesScope

string

资源类型排除范围,多个资源类型用半角逗号(,)分隔。

mse.cluster,slb.loadbalancer

示例 1:根据资源标签自动转组

{
  "RuleName": "A 项目线上资源自动转组",
  "RuleDesc": "带有标签 {\"env\": \"online\"} 和 {\"project\": \"A\"} 的资源转移到资源组 rg-aek2********qcy",
  "RuleType": "custom_condition",
  "RuleContents": [
    {
      "AutoGroupingScopeCondition": "{\"children\":[{\"desired\":\"{\\\"env\\\":\\\"online\\\", \\\"project\\\":\\\"A\\\"}\",\"featurePath\":\"$.tags\",\"featureSource\":\"RESOURCE\",\"operator\":\"TagMatchAll\"}],\"operator\":\"and\"}",
      "TargetResourceGroupCondition": "{\"children\":[{\"desired\":\"rg-aek2********qcy\",\"featurePath\":\"$.resourceGroupId\",\"featureSource\":\"RESOURCE\",\"operator\":\"StringEquals\"}],\"operator\":\"and\"}"
    }
  ]
}

示例 2:云盘跟随 ECS 实例转组

{
  "RuleName": "云盘跟随 ECS 实例转组",
  "RuleDesc": "当云盘挂载到 ECS 实例或 ECS 实例转组时,与之关联的云盘将自动转入关联 ECS 实例所在的资源组",
  "RuleType": "associated_transfer",
  "ResourceTypesScope": "ecs.disk",
  "RuleContents": [
    {
      "TargetResourceGroupCondition": "{\"desired\":\"$.ResourceGroupId\",\"desiredSource\":\"RESOURCE_RELATIONSHIP_ACS::ECS::Instance\",\"featurePath\":\"$.ResourceGroupId\",\"featureSource\":\"CONFIGURATION\",\"operator\":\"StringEquals\"}"
    }
  ]
}

返回参数

名称

类型

描述

示例值

object

返回结果。

RequestId

string

请求 ID。

F7701451-340B-5CB3-AEA7-7D831F7F38C0

RuleId

string

规则 ID。

gr-acfo******hy6a

示例

正常返回示例

JSON格式

{
  "RequestId": "F7701451-340B-5CB3-AEA7-7D831F7F38C0",
  "RuleId": "gr-acfo******hy6a"
}

错误码

HTTP status code

错误码

错误信息

描述

400 Invalid.AssociatedTransferRule.AlreadyExisted The associated transfer rule already exists. 关联转组规则已经存在。
400 InvalidParameter.ResourceTypesScope The parameter ResourceTypesScope is invalid. 参数ResourceTypesScope无效。
400 InvalidParameter.ExcludeResourceTypesScope The parameter ExcludeResourceTypesScope is invalid. 参数ExcludeResourceTypesScope无效。
400 InvalidParameter.ResourceGroupIdsScope The parameter ResourceGroupIdsScope is invalid. 参数ResourceGroupIdsScope无效。
400 InvalidParameter.ExcludeResourceGroupIdsScope The parameter ExcludeResourceGroupIdsScope is invalid. 参数ExcludeResourceGroupIdsScope无效。
400 InvalidParameterCombination.BothRegionIdScopes The combination of parameters RegionIdsScope and ExcludeRegionIdsScope is not allowed. Please select only one of these parameters. RegionIdsScope和ExcludeRegionIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400 InvalidParameterCombination.BothResourceGroupIdScopes The combination of parameters ResourceGroupIdsScope and ExcludeResourceGroupIdsScope is not allowed. Please select only one of these parameters. ResourceGroupIdsScope和ExcludeResourceGroupIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400 InvalidParameterCombination.BothResourceIdScopes The combination of parameters ResourceIdsScope and ExcludeResourceIdsScope is not allowed. Please select only one of these parameters. ResourceIdsScope和ExcludeResourceIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400 InvalidParameterCombination.BothResourceTypeScopes The combination of parameters ResourceTypesScope and ExcludeResourceTypesScope is not allowed. Please select only one of these parameters. ResourceTypesScope和ExcludeResourceTypesScope是互斥的。同一个请求中只能指定其中一个参数。
400 InvalidParameter.RuleContents The parameter RuleContents is invalid. RuleContents 参数非法。
400 MissingParameter.RuleContents The parameter RuleContents is required. RuleContents是必要参数。
409 AutoGroupingNotEnabled The auto grouping is disabled. 自动转组已禁用。
409 QuotaExceeded.RuleContent The number of rule contents exceeds the quota. 创建的分组条件内容数量超过限制。
409 QuotaExceeded.GroupingRule The number of grouping rules exceeds the quota. 分组条件数量超过限制。

访问错误中心查看更多错误码。

变更历史

更多信息,参考变更详情