Remove tags
Remove tags from Simple Log Service resources by calling the UntagResources operation.
Prerequisites
-
Simple Log Service is activated. For more information, see Activate Simple Log Service.
-
The Simple Log Service SDK for Python is initialized. For more information, see Initialize Simple Log Service SDK for Python.
Parameter description
def untag_resources(self, resource_type, resource_id, *tag_keys):
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
resource_type |
String |
Yes |
The resource type. Valid values:
|
project |
|
resource_id |
String |
Yes |
The resource ID. If resource_type is The format of resource_id varies by resource_type:
|
ali-test-project |
|
tag_keys |
String |
Yes |
The tag keys to remove. |
key1 |
Response parameters
For more information about response parameters, see UntagResources.
Sample code
import os
from aliyun.log import LogClient
# Specify a Simple Log Service endpoint.
endpoint = "ap-southeast-1.log.aliyuncs.com"# In this example, the AccessKey ID and AccessKey Secret are obtained from environment variables.
access_key_id = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_ID', '')
access_key_secret = os.environ.get('ALIBABA_CLOUD_ACCESS_KEY_SECRET', '')
# Create a client for Simple Log Service.
client = LogClient(endpoint, access_key_id, access_key_secret)
def print_tag():
for res in client.list_tag_resources(resource_type, resource_id):
for tag in res.get_tags():
print(tag.get_resource_id(), ' ', tag.get_tag_key(), ' : ', tag.get_tag_value())
def untag_project():
print("List project resource tags")
print_tag()
client.untag_resources(resource_type, resource_id, tag_keys)
print('----------after unbinding----------')
print_tag()
def untag_logstore():
print("List logstore resource tags")
print_tag()
client.untag_resources(resource_type, resource_id, tag_keys)
print('----------after unbinding----------')
print_tag()
if __name__ == '__main__':
project_name = "ali-test-project"
logstore_name = "test-logs"print('untag_project:')
resource_type = 'project'
resource_id = project_name
tag_keys = 'proj1'
untag_project()
print('untag_logstore:')
resource_type = 'logstore'
resource_id = project_name + '#' + logstore_name
tag_keys = 'log1'
untag_logstore()
Sample response
untag_project:
List logstore resource tags
ali-test-project ack.aliyun.com : ca671eef738704644970a12a34350007c
ali-test-project proj2 : v2
ali-test-project proj1 : v1
----------after unbinding----------
ali-test-project proj2 : v2
ali-test-project ack.aliyun.com : ca671eef738704644970a12a34350007c
untag_logstore:
List logstore resource tags
ali-test-project#test-logs log2 : v2
ali-test-project#test-logs log1 : v1
----------after unbinding----------
ali-test-project#test-logs log2 : v2
Process finished with exit code 0
References
-
For more information about the APIs for managing tags, see the following topics:
-
More sample code is available in the Alibaba Cloud Simple Log Service SDK for Python GitHub repository.