文档

TagResources - 为云资源创建并绑定标签

更新时间:

为指定的多个云产品的多个云资源统一创建并绑定标签。

接口说明

标签是云资源的标识,可以帮助您从不同维度对具有相同特征的云资源进行分类、搜索和聚合,让资源管理变得更加轻松。更多信息,请参见标签概述

支持标签的云服务,请参见支持标签的云服务

调试

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

授权信息

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

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用背景高亮的方式表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
tag:TagResourcesWrite
  • TagVirtual
    acs:tag:{#regionId}:{#accountId}:*

请求参数

名称类型必填描述示例值
RegionIdstring

地域 ID。取值:

  • 对于中心化部署的云服务,您可以填写通用地域cn-hangzhou,或者参照标签支持的中心化云服务的对应地域填写资源对应的地域 ID。
  • 对于非中心化部署的云服务,您需要填写资源所属的地域 ID。
cn-hangzhou
Tagsstring

标签键和标签值。键值对取值范围:1~10。

如果指定多个标签,则会为指定资源同时创建并绑定该多个标签。

约束如下:

  • 标签键长度范围:1~128 个字符。
  • 标签值长度范围:1~128 个字符。
  • 区分大小写。
  • 同一个资源上的同一个标签键只能对应一个标签值。如果您尝试添加已有标签键,则对应的标签值会更新为新值。
{"k1":"v1","k2":"v2"}
ResourceARNarray

资源 ARN(Aliyun Resource Name)。

string

资源 ARN(Aliyun Resource Name)。

N 的取值范围:1~50。

资源 ARN 的格式:arn:acs:${ProductCode}:${Region}:${Account}:${ResourceType}/${ResourceId}。各字段含义如下:

  • ProductCode:云服务 code。从 ListSupportResourceTypes 返回参数中获取。
  • Region:资源所属的地域 ID。支持使用星号(*)表示当前地域。
  • Account:资源所属的阿里云账号(主账号)ID。支持使用星号(*)表示当前登录的阿里云账号(主账号)。
  • ResourceType:资源类型。从 ListSupportResourceTypes 返回参数中获取。
  • ResourceId:资源 ID。
说明 ResourceARN 支持传递资源组、操作审计和资源管理的ProductCodeResourceType
arn:acs:vpc:cn-hangzhou:123456789****:vpc/vpc-bp19dd90tkt6tz7wu****

关于公共请求参数的详情,请参见公共参数

返回参数

名称类型描述示例值
object

返回参数。

RequestIdstring

请求 ID。

72086426-9F8C-4A60-852B-864048FD1199
FailedResourcesobject []

失败资源信息。

说明
  • 创建并绑定标签成功时,返回的FailedResources为空。
  • 创建并绑定标签失败或部分失败时,返回的FailedResources会显示失败资源的详细信息。
  • ResourceARNstring

    失败资源 ARN。

    arn:acs:vpc:cn-hangzhou:123456789****:vpc/vpc-bp19dd90tkt6tz7wu****
    Resultobject

    错误结果。

    Codestring

    错误码。

    InvalidResourceId.NotFound
    Messagestring

    错误信息。

    The specified ResourceIds are not found in our records.

    示例

    正常返回示例

    JSON格式

    {
      "RequestId": "72086426-9F8C-4A60-852B-864048FD1199",
      "FailedResources": {
        "FailedResource": [
          {
            "ResourceARN": "arn:acs:vpc:cn-hangzhou:123456789****:vpc/vpc-bp19dd90tkt6tz7wu****",
            "Result": {
              "Code": "InvalidResourceId.NotFound",
              "Message": "The specified ResourceIds are not found in our records."
            }
          }
        ]
      }
    }

    错误码

    HTTP status code错误码错误信息描述
    400InvalidResourceARN.RegionThe Region specified in the ResourceARN parameter does not match the RegionId parameter, specifically: %s.ResourceARN中的Region与参数RegionId不匹配,它们分别是:%s
    400InvalidResourceARN.AccountThe Account specified in the ResourceARN parameter does not match the actual account, specifically: %s.ResourceARN中的Account与实际用户不吻合,分别是:%s
    400InvalidResourceARN.FormatErrorThe format of parameter ResourceARN: %s is not valid, for the correct format, you can refer to the Recommend.ResourceARN的格式不符合规范,正确的格式请参考错误诊断。
    400InvalidParameter.ResourceTypeThe parameter resource type: %s in ResourceARN is not valid or not support.在ResourceARN中的ResourceType:%s 不合法或不被支持。
    400InvalidParameter.ServiceCodeThe parameter service code: %s in ResourceARN is not valid or not support.ResourceARN中的ServiceCode:%s 不合法或未被支持。
    400InvalidParameter.TagKeyThe TagKey parameter is invalid. The following TagKeys are invalid: %s.参数中存在不合法的标签键,不合法的标签键如下:%s
    400InvalidParameter.TagValueThe TagValue parameter is invalid. The following TagValues are invalid: %s.参数中包含不合法的标签值,不合法的标签值如下:%s
    400InvalidParameter.TagsThe Tags parameter cannot be empty, and JSON parsing should adhere to the format of a Map.参数Tags不能为空,JSON解析需符合Map的格式,比如 {"key":"value"}
    403Duplicate.TagKeyThe Tag.N.Key contains duplicate keys.参数包含重复标签键。
    403InvalidParameter.CategoryThe specified Category is invalid. Valid values are Custom and System.标签类型非法,合法值为Custom,System。
    403MissingParameter.CreatebyYou must specify Createby.操作者参数不可为空。
    403MissingParameter.ResourceIdsYou must specify ResourceIds.资源列表参数不可为空。
    403NoPermission.OperatorThe user is not authorized to operate on the specified resource.该用户没有权限操作。
    403NoPermissionKey.CategorySome keys cannot be modified because the user does not have permission.某些key的标签类型没有操作权限。
    403NoPermissionKey.OperatorYou are not authorized to operate the tag key.该用户没有操作此标签键权限。
    403NumberExceed.ResourceIdsThe maximum number of ResourceIds is exceeded.资源列表参数数量超限。
    403NumberExceed.TagsThe maximum number of Tags is exceeded.标签参数数量超限。
    403QuotaExceed.TagsPerResourceThe maximum number of tags for each resource is exceeded.每个资源上的标签数量有限制,目前有资源已经超限。
    404Missing.TagKeyTag.N.Value has been specified and you must specify Tag.N.Key.一对键值对,对应的TagValue缺失相同N的TagKey。
    404MissingParameter.AliUidYou must specify AliUid.缺失用户UID参数。
    404MissingParameter.BidYou must specify Bid.bid参数不可为空。
    404MissingParameter.TagKeyYou must specify TagKey.标签键参数不可为空。

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

    变更历史

    变更时间变更内容概要操作
    2024-02-27OpenAPI 错误码发生变更看变更集
    变更项变更内容
    错误码OpenAPI 错误码发生变更
      错误码 400 变更
      错误码 403 变更
      删除错误码:404
    • 本页导读 (1)
    文档反馈