You can call the TagResources operation to create and add tags to instances.

If you have a large number of instances, you can create multiple tags and add these tags to the instances. Then, you can filter these instances by tag.

  • A tag consists of a key and a value. Each key must be unique in a region for an Alibaba Cloud account. Different keys can be mapped to the same value.
  • If the tag that you specify does not exist, this tag is automatically created and added to the specified instance.
  • If the key of the specified tag is the same as that of an existing tag, the specified tag overwrites the existing tag.
  • You can add up to 20 tags to an instance.
  • You can add tags to up to 50 instances in each call.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes TagResources

The operation that you want to perform. Set the value to TagResources.

RegionId String Yes cn-hangzhou

The ID of the region. You can call the DescribeRegions operation to query the most recent region list.

ResourceType String Yes INSTANCE

The type of the resource. Set the value to INSTANCE.

ResourceId.N String Yes rm-uf6wjk5xxxxxxx

The IDs of the instances. You can add tags to N instances at a time. Valid values of N: 1 to 50.

Tag.N.Key String Yes testkey1

The key of the tag that you want to add to the instance. You can create N tag keys at a time. Valid values of N: 1 to 20. The value of this parameter cannot be an empty string.

Tag.N.Value String No testvalue1

The tag value that is associated with the specified tag key. You can create N tag values at a time. Valid values of N: 1 to 20. This parameter can be an empty string.

Response parameters

Parameter Type Example Description
RequestId String 224DB9F7-3100-4899-AB9C-C938BCCB43E7

The ID of the request.

Examples

Sample requests

http(s)://rds.aliyuncs.com/?Action=TagResources
&RegionId=cn-hangzhou
&ResourceType=INSTANCE
&ResourceId.1=rm-uf6wjk5xxxxxxx
&Tag.1.Key=testkey1
&Tag.1.Value=testvalue1
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<TagResourcesResponse>
<RequestId>224DB9F7-3100-4899-AB9C-C938BCCB43E7</RequestId>
</TagResourcesResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "RequestId" : "224DB9F7-3100-4899-AB9C-C938BCCB43E7"
}

Error codes

HTTP status code Error code Error message Description
400 NumberExceed.Tags The maximum number of Tags is exceeded. The maximum value is 20. The error message returned because the number of created tags exceeds the upper limit. You can create up to 20 tags for an instance.
400 MissingParameter The parameter - Tags should not be null The error message returned because the Tag.N.Key parameter is not specified.
400 InvalidTagKey.Malformed The Tag.N.Key parameter is blank The error message returned because the value of the Tag.N.Key parameter is an empty string.
400 InvalidTagValue.Malformed The Tag.N.Value parameter is blank The error message returned because the value of the Tag.N.Value parameter is empty.
400 Duplicate.TagKey The Tag.N.Key contain duplicate key. The error message returned because the Tag.N.Key parameter specifies a duplicate key.
400 OperationDenied.QuotaExceed The maximum number of Tags is exceeded. The error message returned because the number of created tags exceeds the upper limit.
400 NumberExceed.ResourceIds The maximum number of ResourceIds is exceeded. The maximum value is 50. The error message returned because the number of instance IDs exceeds the upper limit. You can specify up to 50 instance IDs.
400 InvalidTagKey.Malformed The operator is not permission for the system tag The error message returned because you are not authorized to perform operations on system tags.
400 Request.NotFound The requested resource is not available. The error message returned because the resource you requested is unavailable.
400 InvalidTagValue.Malformed The Tag.N.Value parameter is invalid. The error message returned because the value of the Tag.N.Value parameter is invalid.

For a list of error codes, visit the API Error Center.