Call the TagResources API to attach tags to resources.
Prerequisites
Simple Log Service is activated. For more information, see Activate Simple Log Service.
Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
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 |
resource_id | String | Yes | The resource ID. If resource_type is When resource_type has different enumeration values, the parameters corresponding to resource_id are as follows:
| 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
For more information about the APIs for managing tags, see the following topics:
For more sample code, see Alibaba Cloud Simple Log Service SDK for Python on GitHub.