All Products
Search
Document Center

Simple Log Service:Attach tags

Last Updated:Dec 30, 2024

Call the TagResources API to attach tags to resources.

Prerequisites

Parameter description

def tag_resources(self, resource_type, resource_id, **tags):

Request parameters

Parameter

Type

Required

Description

Example

resource_type

String

Yes

The type of the resource. The following types are supported:

  • project

  • logstore

  • dashboard

  • machinegroup

  • logtailconfig

project

resource_id

String

Yes

The resource ID. If resource_type is project, resource_id is projectName. Otherwise, resource_id is projectName#subResourceId.

When resource_type has different enumeration values, the parameters corresponding to resource_id are as follows:

  • project: projectName

  • logstore: projectName#logstore

  • dashboard: projectName#dashboard

  • machinegroup: projectName#machinegroup

  • logtailconfig: projectName#logtailconfig

ali-test-project

tags

Dictionary

Yes

The list of tags. Up to 20 key-value pairs of tags are supported at a time.

{'key1': 'value1', 'key2': 'value2'}

Response parameters

For information about the response parameters, see TagResources.

Sample code

import os
from aliyun.log import LogClient


def tag_project(client, project):
    tags = {'key1': 'value1', 'key2': 'value2'}
    client.tag_resources('project', project, **tags)


def tag_logstore(client, project, logstore):
    tags = {'key1': 'value1', 'key2': 'value2'}
    client.tag_resources('logstore', project + '#' + logstore, **tags)


if __name__ == '__main__':
    # Specify a Simple Log Service endpoint.
    endpoint = "cn-hangzhou.log.aliyuncs.com"
    # In this example, the AccessKey ID and AccessKey secret are obtained from environment variables.
    accessKeyId = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
    accessKey = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')

    project_name = "ali-test-project"
    logstore_name = "test-logstore"

    client = LogClient(endpoint, accessKeyId, accessKey, "")
    tag_project(client, project_name)
    tag_logstore(client, project_name, logstore_name)

References