List resource tags
You can call the ListTagResources operation to query the tags that are attached to resources.
Prerequisites
Simple Log Service is activated. For more information, see Enable Log Service.
Simple Log Service SDK for Java is initialized. For more information, see Initialize Simple Log Service SDK for Java.
Parameter description
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
resourceType |
String |
Yes |
The resource type. Valid values:
|
project |
|
resourceId |
List<String> |
No |
The resource ID. You must specify either resourceId or tagList. The format of resourceId varies based on the value of resourceType:
|
ali-test-project |
|
tagList |
Map<String, String> |
No |
The tags used to filter resources by exact match. You must specify either resourceId or tagList. You can specify up to 20 key-value pairs. If you specify a key such as |
{t1=k1} |
Response parameters
For more information about the response parameters, see ListTagResources.
Sample code
import com.aliyun.openservices.log.Client;
import com.aliyun.openservices.log.common.TagResource;
import com.aliyun.openservices.log.exception.LogException;
import com.aliyun.openservices.log.request.ListTagResourcesRequest;
import com.aliyun.openservices.log.response.ListTagResourcesResponse;
import java.util.*;
public class ListTagResourcesExample {
// In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
static String accessId = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
static String accessKey = System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
// Specify a Simple Log Service endpoint.
static String host = "ap-southeast-1.log.aliyuncs.com";
// Initialize a client for Simple Log Service.
static Client client = new Client(host, accessId, accessKey);
private static final String RESOURCE_TYPE = "project";
private static final String RESOURCE_ID = "ali-peoject-test1";
public static void main(String[] args) throws LogException {
ListTagResourcesResponse resources = client.listTagResources(new ListTagResourcesRequest(RESOURCE_TYPE,
Arrays.asList(RESOURCE_ID), Collections.singletonMap("t1", "k1")));
List<TagResource> tagResources = resources.getTagResources();
for (TagResource tagResource : tagResources) {
System.out.println("Resource ID: " + tagResource.getResourceId());
System.out.println("Resource Type: " + tagResource.getResourceType());
System.out.println("Tag Key: " + tagResource.getTagKey());
System.out.println("Tag Value: " + tagResource.getTagValue());
}
}
}
References
-
For more information about the APIs for managing tags, see the following topics: