List resource tags

Updated at:

You can call the ListTagResources operation to query the tags that are attached to resources.

Prerequisites

Parameter description

Request parameters

Parameter

Type

Required

Description

Example

resourceType

String

Yes

The resource type. Valid values:

  • project

  • logstore

  • dashboard

  • machinegroup

  • logtailconfig

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:

  • project: projectName

  • logstore: projectName#logstore

  • dashboard: projectName#dashboard

  • machinegroup: projectName#machinegroup

  • logtailconfig: projectName#logtailconfig

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 "test-key", only resources that have a tag with the key "test-key" are returned. If you set the value to null, only the key is used for filtering.

{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