All Products
Search
Document Center

Elastic Compute Service:ListTagResources

Last Updated:Aug 07, 2026

Queries the tags that are bound to one or more ECS resources.

Operation description

Operation description

Specify at least one of the following parameters in the request to determine the query object.

  • ResourceId.N

  • Tag.N (Tag.N.Key and Tag.N.Value)

  • TagFilter.N

If you specify the following parameters at the same time, the response contains only ECS resources that meet both conditions.

  • Tag.N and ResourceId.N

  • TagFilter.N and ResourceId.N

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:ListTagResources

get

*All Resource

*

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

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

cn-hangzhou

RegionId

string

Yes

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

cn-hangzhou

NextToken

string

No

The token used to start the next query.

caeba0bbb2be03f84eb48b699f0a4883

ResourceType

string

Yes

The resource type. Valid values:

  • instance: ECS instance.

  • disk: cloud disk.

  • snapshot: snapshot.

  • image: image.

  • securitygroup: security group.

  • volume: storage volume.

  • eni: Elastic Network Interface (ENI).

  • ddh: dedicated host.

  • ddhcluster: dedicated host cluster.

  • keypair: SSH key pair.

  • launchtemplate: launch template.

  • reservedinstance: reserved instance.

  • snapshotpolicy: automatic snapshot policy.

  • elasticityassurance: elasticity assurance.

  • capacityreservation: capacity reservation.

  • command: Cloud Assistant command.

  • invocation: Cloud Assistant command execution or file sending result.

  • activation: Cloud Assistant managed instance activation code.

  • managedinstance: Cloud Assistant managed instance.

instance

ResourceId

array

No

The ECS resource ID. Valid values of N: 1 to 50.

i-bp1j6qtvdm8w0z1o****

string

No

The ECS resource ID. Valid values of N: 1 to 50.

i-bp1j6qtvdm8w0z1o****

Tag

array<object>

No

The tags.

object

No

The tags.

Key

string

No

The tag key used to perform an exact search for ECS resources. The tag key must be 1 to 128 characters in length. Valid values of N: 1 to 20.

Usage notes of the Tag.N parameter:

  • Method 1: Used to perform an exact search for ECS resources that have the specified tags bound. Each tag is a key-value pair.

    • If you specify only Tag.N.Key, all resources associated with the tag key are returned.

    • If you specify only Tag.N.Value, the InvalidParameter.TagValue error is returned.

    • If you specify multiple tag key-value pairs at the same time, only ECS resources that match all the specified tag key-value pairs are returned.

  • Method 2: Used to query resource information in non-default resource groups. Set Key to acs:rm:rgId and set the corresponding Value to the resource group ID.

    • If Key is set to acs:rm:rgId, Value can only be set to a non-default resource group ID. If the specified resource group ID is the default resource group, an error message is returned.

    • If Key is set to acs:rm:rgId, you cannot specify other tag key-value pairs. If you use multiple Tag.N parameters to query resources by resource group and tags at the same time, an error message is returned.

TestKey

Value

string

No

The tag value used to perform an exact search for ECS resources. The tag value must be 1 to 128 characters in length. Valid values of N: 1 to 20.

Note

If Key=acs:rm:rgId, this parameter can only be set to a resource group ID, and the resource group ID cannot be the default resource group.

TestValue

TagFilter

array<object>

No

The tag filter rules.

Note

This parameter is in invitational preview and is not publicly available.

object

No

The tag filter rules.

TagValues

array

No

The tag value used to perform a fuzzy search for ECS resources. The tag value must be 1 to 128 characters in length. Valid values of N: 1 to 5. For the metric description, see the TagFilter.N.TagKey parameter description.

TestTagFilter

string

No

The tag value used to perform a fuzzy search for ECS resources. The tag value must be 1 to 128 characters in length. Valid values of N: 1 to 5. For the metric description, see the TagFilter.N.TagKey parameter description.

TestTagFilter

TagKey

string

No

The tag key used to perform a fuzzy search for ECS resources. The tag key must be 1 to 128 characters in length. Valid values of N: 1 to 5.

TagFilter.N is used to perform a fuzzy search for ECS resources that have the specified tags bound. It consists of a key and one or more values. A fuzzy search may have a latency of up to 2 seconds and supports only scenarios where the number of resources after fuzzy filtering is less than or equal to 5,000.

  • When you perform a fuzzy search for ECS resources by tag key (TagFilter.N.TagKey), the tag value (TagFilter.N.TagValues.N) must be empty. For example, to perform a fuzzy search for ECS resources whose tag key is environment, you can set TagFilter.1.TagKey to env* (prefix match), *env* (infix match), or env (exact match), and TagFilter.1.TagValues must be empty.

  • When you perform a fuzzy search for ECS resources by tag value (TagFilter.N.TagValues.N), the tag key (TagFilter.N.TagKey) must be set to an exact value. For example, to perform a fuzzy search for ECS resources whose tag key is env and tag value is product, TagFilter.1.TagKey must be set to the exact value env, and TagFilter.1.TagValues.1 can be set to proc* (prefix match), *proc* (infix match), or proc (exact match). Only one search method can be used for the same TagKey. If multiple search methods are specified, the first method takes precedence.

  • Tag keys have an AND relationship. Only ECS resources that match all specified tag keys are returned.

  • Tag values under the same tag key have an OR relationship. ECS resources that match any of the tag values specified for a tag key are returned.

Note

The TagFilter.N and Tag.N parameters cannot be used at the same time. Otherwise, an error message is returned.

env

Response elements

Element

Type

Description

Example

object

NextToken

string

The token used to start the next query.

caeba0bbb2be03f84eb48b699f0a4883

RequestId

string

The request ID.

484256DA-D816-44D2-9D86-B6EE4D5BA78C

TagResources

object

TagResource

array<object>

The collection of resources and their tags, which contains information such as the resource ID, resource type, and tag key-value pairs.

object

TagValue

string

The tag value.

TestValue

ResourceType

string

The resource type. Valid values:

  • instance: An ECS instance.

  • disk: A disk.

  • snapshot: A snapshot.

  • image: An image.

  • securitygroup: A security group.

  • volume: A volume.

  • eni: An elastic network interface.

  • ddh: A dedicated host.

  • ddhcluster: A dedicated host cluster.

  • keypair: An SSH key pair.

  • launchtemplate: A launch template.

  • reservedinstance: A reserved instance.

  • snapshotpolicy: An automatic snapshot policy.

  • elasticityassurance: An elasticity assurance.

  • capacityreservation: A capacity reservation.

  • command: A Cloud Assistant command.

  • invocation: The result of a Cloud Assistant command execution.

  • activation: An activation code for a managed instance.

  • managedinstance: A managed instance.

instance

ResourceId

string

The resource ID.

i-bp1j6qtvdm8w0z1o****

TagKey

string

The tag key.

TestKey

Examples

Success response

JSON format

{
  "NextToken": "caeba0bbb2be03f84eb48b699f0a4883",
  "RequestId": "484256DA-D816-44D2-9D86-B6EE4D5BA78C",
  "TagResources": {
    "TagResource": [
      {
        "TagValue": "TestValue",
        "ResourceType": "instance",
        "ResourceId": "i-bp1j6qtvdm8w0z1o****",
        "TagKey": "TestKey"
      }
    ]
  }
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidDefaultResourceGroup.NotSupported The specified parameter Tag is not support for default resource group. The default resource group cannot be queried.
400 InvalidTag.NotSupported You can only specify Tag for either resource tag or resource group. Resource groups and tags cannot be queried at the same time.
400 NumberExceed.ResourceIds The ResourceIds parameter's number is exceed , Valid : 50. The number of ResourceIds parameters specified exceeds the limit.
400 NumberExceed.Tags The Tags parameter's number is exceed , Valid : 20. The number of labels specified exceeds the limit.
400 Duplicate.TagKey The Tag.N.Key contain duplicate key. The specified tag key already exists. Tag keys must be unique.
400 InvalidTagKey.Malformed The specified Tag.n.Key is not valid. The specified Tag.N.Key parameter is invalid.
400 InvalidTagValue.Malformed The specified Tag.n.Value is not valid. The specified tag value is invalid.
400 OperationDenied.QuotaExceed The quota of tags on resource is beyond permitted range.
400 InvalidTag.Mismatch The specified Tag.n.Key and Tag.n.Value are not match. The specified Tag.N.Key and Tag.N.Value parameters do not correspond to each other.
400 InvalidTagCount The specified tags are beyond the permitted range. The number of specified tags exceeds the upper limit.
400 Invalid.Scope The specified scope is invalid.
400 InvalidTags.MalFormed The tags must be empty, when the tagFilters is not empty.
500 ServiceUnavailable The service is unavailable, please try again later.
500 InternalError The process of creating snapshot has failed due to some unknown error. The snapshot cannot be created.
403 PermissionDenied.TagOwnerBid The specified operator not have permission to set TagOwnerBid value.
403 PermissionDenied.TagOwnerUid The specified operator not have permission to set TagOwnerUid value. You are not authorized to specify the TagOwnerUid parameter.
403 PermissionDenied.Scope The specified operator not have permission to set Scope value. You are not authorized to specify the Scope parameter.
403 InvalidResourceId.NotSupported The specified ResourceId does not support tagging.
403 NoPermission.Tag The operator is not permission for the tag. You are not authorized to manage the tag.
403 BothEmpty.TagsAndResources The specified Tags and ResourcesIds are not allow to both empty. The parameter passed in must contain Tags or
403 PermissionDenied.TagsFuzzyQuery The specified operator has not permission to query fuzzy tags.
403 NumberExceed.TagValues The number of the specified TagValues is beyond permitted range, the max is 5.
403 InvalidFilter.Malformed The specified Filter is not valid.
403 InvalidTagFilter.Malformed The specified TagFilter is not valid.
403 Invalid.NextToken The specified NextToken is not valid.
404 InvalidRegionId.NotFound The RegionId provided does not exist in our records. Region information error
404 MissingParameter.ResourceIds The parameter - ResourceIds.N should not be null.
404 MissingParameter.TagOwnerUid The parameter - TagOwnerUid should not be null.
404 MissingParameter.TagOwnerBid The parameter - TagOwnerBid should not be null.
404 MissingParameter.ResourceType The parameter - ResourceType should not be null. The ResourceType parameter is required.
404 MissingParameter.Tags The parameter - Tags should not be null.
404 MissingParameter.RegionId The parameter - RegionId should not be null.
404 InvalidResourceId.NotFound The specified ResourceIds are not found in our records. The specified resource does not exist. Check whether the ResourceId parameter is correct.
404 InvalidResourceType.NotFound The ResourceType provided does not exist in our records. The specified resource type does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.