All Products
Search
Document Center

Resource Management:ListResourcesByTag

Last Updated:Nov 28, 2024

Queries resources to which a specified tag is added or resources to which a specified tag is not added.

Operation description

This topic provides an example on how to call the API operation in the China (Shenzhen) region to query virtual private clouds (VPCs) to which the tag key k1 is added. The response shows that the tag key is added to two VPCs.

Debugging

You can run this interface directly in OpenAPI Explorer, saving you the trouble of calculating signatures. After running successfully, OpenAPI Explorer can automatically generate SDK code samples.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
tag:ListResourcesByTagget
*All Resources
*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
RegionIdstringYes

The region ID.

For more information about region IDs, see Endpoints .

cn-shenzhen
NextTokenstringNo

The token that is used to start the next query.

caeba0bbb2be03f84eb48b699f0a****
MaxResultintegerNo

The number of entries to return on each page.

Default value: 50. Maximum value: 1000.

50
ResourceTypestringYes

The resource type. This parameter specifies a filter condition for the query.

  • If you set the FuzzyType parameter to EQUAL, you can set this parameter to a value obtained from the response of the ListSupportResourceTypes operation.
  • If you set the FuzzyType parameter to NOT, you can set this parameter to a resource type provided in Types of resources that support queries based on the NOT operator.
ALIYUN::VPC::VPC
FuzzyTypestringNo

The type of the query. Valid values:

  • EQUAL: exact match for resources to which the specified tag is added. This is the default value.
  • NOT: exact match for resources to which the specified tag is not added.
EQUAL
TagFilter.ValuestringNo

The tag value. This parameter specifies a filter condition for the query.

The tag value can be up to 128 characters in length and cannot contain http:// or https://.

v1
TagFilter.KeystringYes

The tag key. This parameter specifies a filter condition for the query.

The tag key can be a maximum of 128 characters in length. It cannot contain http:// or https:// and cannot start with acs: or aliyun.

k1
IncludeAllTagsbooleanNo

Specifies whether to return the information of tags added to the resources. Valid values:

  • False: does not return the information of tags added to the resources. This is the default value.
  • True: returns the information of all tags added to the resources.
False

Types of resources that support queries based on the NOT operator:

  • ALIYUN::ADB::CLUSTER
  • ALIYUN::ALB::ACL
  • ALIYUN::ALB::LOADBALANCER
  • ALIYUN::ALB::SECURITYPOLICY
  • ALIYUN::ALB::SERVERGROUP
  • ALIYUN::ALIDNS::DOMAIN
  • ALIYUN::BASTIONHOST::INSTANCE
  • ALIYUN::BPSTUDIO::APPLICATION
  • ALIYUN::BPSTUDIO::TEMPLATE
  • ALIYUN::CAS::INSTANCE
  • ALIYUN::CDN::DOMAIN
  • ALIYUN::CDS::CLUSTER
  • ALIYUN::CEN::BANDWIDTHPACKAGE
  • ALIYUN::CEN::CEN
  • ALIYUN::CS::CLUSTER
  • ALIYUN::DBAUDIT::INSTANCE
  • ALIYUN::DCDN::DOMAIN
  • ALIYUN::DDOSBGP::INSTANCE
  • ALIYUN::DDOSCOO::INSTANCE
  • ALIYUN::DDS::INSTANCE
  • ALIYUN::DRDS::INSTANCE
  • ALIYUN::ECS::DDH
  • ALIYUN::ECS::DDHCLUSTER
  • ALIYUN::ECS::DISK
  • ALIYUN::ECS::ENI
  • ALIYUN::ECS::INSTANCE
  • ALIYUN::ECS::KEYPAIR
  • ALIYUN::ECS::LAUNCHTEMPLATE
  • ALIYUN::ECS::SECURITYGROUP
  • ALIYUN::ECS::SNAPSHOT
  • ALIYUN::EDAS::APPLICATION
  • ALIYUN::EDAS::CLUSTER
  • ALIYUN::ELASTICSEARCH::INSTANCE
  • ALIYUN::EMR::CLUSTER
  • ALIYUN::EMR::FLOWPROJECT
  • ALIYUN::HBR::CLIENT
  • ALIYUN::HBR::HANAINSTANCE
  • ALIYUN::HBR::VAULT
  • ALIYUN::KVSTORE::INSTANCE
  • ALIYUN::MULTIMOD::CLUSTER
  • ALIYUN::OCEANBASE::INSTANCE
  • ALIYUN::OOS::EXECUTION
  • ALIYUN::OOS::PARAMETER
  • ALIYUN::OOS::SECRETPARAMETER
  • ALIYUN::OOS::STATECONFIGURATION
  • ALIYUN::OOS::TEMPLATE
  • ALIYUN::OSS::BUCKET
  • ALIYUN::OUTBOUNDBOT::INSTANCE
  • ALIYUN::POLARDB::CLUSTER
  • ALIYUN::PVTZ::ZONE
  • ALIYUN::RDS::INSTANCE
  • ALIYUN::VPC::COMMONBANDWIDTHPACKAGE
  • ALIYUN::VPC::EIP
  • ALIYUN::VPC::NATGATEWAY
  • ALIYUN::VPC::VPC

Response parameters

ParameterTypeDescriptionExample
object

The response parameters.

RequestIdstring

The ID of the request.

7D61FF74-61C2-5768-B01F-05FC97F24F35
NextTokenstring

Indicates whether the next query is required.

  • If the value of this parameter is empty ("NextToken": ""), all results are returned, and the next query is not required.
  • If the value of this parameter is not empty, the next query is required, and the value is the token used to start the next query.
caeba0bbb2be03f84eb48b699f0a****
Resourcesarray<object>

The information of the resources.

TagResourceobject

The information of the resources.

ResourceIdstring

The ID of the resource.

vpc-wz9pifyuw26esxd05****
Tagsarray<object>

The information of the tags.

This parameter is returned only if the IncludeAllTags parameter is set to True.

Tagobject

The information of the tags.

Keystring

The tag key.

k1
Valuestring

The tag value.

v1
Categorystring

The type of the tag. Valid values:

  • custom
  • system
custom

Examples

Sample success responses

JSONformat

{
  "RequestId": "7D61FF74-61C2-5768-B01F-05FC97F24F35",
  "NextToken": "caeba0bbb2be03f84eb48b699f0a****",
  "Resources": [
    {
      "ResourceId": "vpc-wz9pifyuw26esxd05****",
      "Tags": [
        {
          "Key": "k1",
          "Value": "v1",
          "Category": "custom"
        }
      ]
    }
  ]
}

Error codes

HTTP status codeError codeError messageDescription
400Invalid.MsgEndPointThe MsgEndPoint is invalid.The MsgEndPoint is invalid.
400Invalid.MsgQueueThe MsgQueue is invalid.The MsgQueue is invalid.
400InvalidParameter.TagsThe specified value of parameter Tags is not valid.The specified value of parameter Tags is not valid.
400InvalidParameter.TagsThe Tags' parameter cannot be empty, and JSON parsing should adhere to the format of a Map.The Tags parameter cannot be empty. JSON parsing must conform to the Map format, for example, {"key":"value"}
400Duplicate.TagKeyThe Tag.N.Key contains duplicate keys, please check the duplicate tag key.Duplicate tag key exists.
400InvalidParameter.TagKeyThe TagKey parameter is invalid. The following TagKeys are invalid: %s.Illegal tag keys exist in the parameter. Illegal tag keys are as follows: %s
400MetaTagKeyHasValueThe specified TagKey already bind tag value-
400NumberExceed.TagKeysThe maximum number of TagKeys is exceeded.The maximum number of tag keys is exceeded.
400InvalidParameter.TagValueThe TagValue parameter is invalid. The following TagValues are invalid: %s.The parameter contains illegal tag values. Illegal tag values are as follows: %s
403Invalid.NextTokenThe parameter NextToken is invalid.The parameter NextToken is invalid.
403InvalidParamter.NextTokenNextToken parameter is illegal.NextToken parameter is illegal.
403FuzzyType.NotSupportFuzzy queries are not supported.Fuzzy queries are not supported.
403NumberExceed.TagsThe maximum number of Tags is exceeded.The maximum number of Tags is exceeded.
403QuotaExceed.TagsPerResourceThe maximum number of tags for each resource is exceeded.The maximum number of tags for each resource is exceeded.
403Duplicate.TagKeyThe Tag.N.Key contains duplicate keys.The Tag.N.Key contains duplicate keys.
403InvalidParameter.KeyThe Key is invalid.-
403InvalidParameter.TagKeyThe Tag.N.Key parameter is invalid.The Tag.N.Key parameter is invalid.
403MetaTagKey.BindingResourcesBinding resource exists for tag key.Binding resource exists for tag key.
403MetaTagKeyNotFoundThe meta tag key is not found.-
403NoPermissionKey.CategorySome keys cannot be modified because the user does not have permission.Some keys cannot be modified because the user does not have permission.
403NoPermissionKey.OperatorYou are not authorized to operate the tag key.You are not authorized to operate the tag key.
403InvalidParameter.CategoryThe specified Category is invalid. Valid values are Custom and System.The specified Category is invalid. Valid values are Custom and System.
403InvalidParameter.TagValueThe Tag.N.Value parameter is invalid.The Tag.N.Value parameter is invalid.
403InvalidParameter.ValueThe Value is invalid.-
404MissingParameter.TagsYou must specify Tags.You must specify Tags.
404Missing.TagKeyTag.N.Value has been specified and you must specify Tag.N.Key.Tag.N.Value has been specified and you must specify Tag.N.Key.
404MissingParameter.KeyThe Key must not be empty.-
404MissingParameter.TagKeyYou must specify TagKey.You must specify TagKey.
404MissingParameter.TagKeyValueParamListThe parameter TagKeyValueParamList must not be null.You must specify TagKeyValueParamList.
404MissingParameter.ValueThe Value must not be empty.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2022-12-06The internal configuration of the API is changed, but the call is not affectedView Change Details
2022-11-21The internal configuration of the API is changed, but the call is not affectedView Change Details