As the number of cloud resources increases, the difficulty in managing the resources also increases. For example, you may be unable to batch collect cost statistics about and perform O&M and monitoring on multiple cloud resources that serve the same purpose or belong to the same application category or organization to ensure that the resources are properly used and efficiently managed. To efficiently manage your resources, you can use tags to categorize the resources. Tags are an important grouping tool that helps you in the horizontal management of personnel, finances, and materials and the fine-grained management of resources.
For more information about tags, see Tag overview.
Scenarios
As the number of Elastic Compute Service (ECS) instances that you create increases, you can use tags to manage, group, and categorize the instances to facilitate instance search and batch operations. Tags are suitable for scenarios that involve resource management, access control, automated O&M, and cost allocation. Example scenarios:
Management of application publishing procedures
Resource tracking and tag-based group search and management
Tag-based and group-based automated O&M by using Alibaba Cloud services such as CloudOps Orchestration Service, Resource Orchestration Service (ROS), Auto Scaling, and Cloud Assistant
Tag-based cost management and cost allocation
Resource-based or role-based access control
The following examples describe how to use tags in two scenarios. For information about more tag scenarios, see Tag overview.
Scenario 1: Optimize the management of ECS resources or automate O&M on ECS resources
You can add different tags to different environments (such as production environments and test environments), operating systems (such as Windows Server and Linux), or client platforms (such as iOS and Android). For example, add the Test:Server-Windows
tag to all ECS instances that are used in a test environment. Then, you can find these ECS instances based on the tags and perform operations on the instances.
Examples of batch operations:
Replace images to deploy applications.
Upgrade patches.
Create security group rules to control network access.
For more information, see Query ECS instances with a specific tag and add the ECS instances to security groups with the same tag.
Use CloudOps Orchestration Service to batch start, stop, or restart ECS instances.
For information about how to batch start ECS instances by using OOS based on tags, see Use OOS to start multiple ECS instances with specific tags at a time.
Use Cloud Assistant to run O&M scripts on multiple ECS instances.
For information about how to run a Cloud Assistant command on ECS instances that have specific tags added, see Manage the executions of Cloud Assistant commands based on tags.
Scenario 2: Manage teams or projects
When you manage teams or projects, you can add tags such as CostCenter:aliyun
to categorize groups, projects, or departments. This way, you can implement itemized billing and cross-authorization based on tags in the Expenses and Costs console.
For more information, see the following topics:
Usage notes
Each tag consists of a key and a value. Each tag key must be unique in a resource.
Before you use tags, you must understand the limits and quotas of tags. For more information, see the Limits section of the "Tag overview" topic.
Create or add tags
Before you create tags, learn about the background information, principles, and examples of tag design. For more information, see the Principles section of the "Best practices for tag design" topic. To create or add tags, perform the steps in this section.
You can add up to 20 tags to a resource. If the number of tags that are added to a resource reaches the upper limit, you must remove some of the tags before you add new tags.
For information about how to batch modify or add tags, see Use OOS to modify a tag value of multiple resources or Use OOS to add tags to multiple ECS resources at a time.
Log on to the ECS console.
In the left-side navigation pane, click Tags.
In the top navigation bar, select the region and resource group to which the resource belongs.
On the Custom Tags tab, click Create Custom Tag.
In the Create Custom Tag dialog box, perform the following steps.
When you create custom tags, you must add the tags to resources. Up to 10 custom tags can be created at the same time, and each custom tag key must be unique. If you want to create tags but do not want to add the tags to resources, create the tags as predefined tags. For more information, see Create a predefined tag.
Create or select tags.
Configure the parameters that are described in the following table.
Parameter
Required
Description
Tag key
Yes
Enter a new tag key or select an existing tag key.
NoteIf you want to create a tag, enter a new tag key. If you want to add an existing tag, select its tag key.
The tag key can be up to 128 characters in length and cannot contain http:// or https://. The tag key cannot start with acs: or aliyun.
You can search for an existing tag key that you want to add. Fuzzy search is supported. Up to 10 tag keys can be added at a time.
Tag value
No
Enter a new tag value or select an existing tag value.
NoteIf you want to add an existing tag, select its tag value.
The tag value can be up to 128 characters in length and cannot contain http:// or https://.
You can search for an existing tag value that you want to add. Fuzzy search is supported. Up to 10 tag values can be added at a time.
Click Next.
Add the tags to resources.
Configure the parameters described in the following table.
Parameter
Description
Example
Method to Specify Resources
Valid values:
Resources: You can select one or more resources to which you want to add tags from the resource list.
Enter Resource IDs: You can enter resource IDs in the Resource ID field.
NoteYou can enter multiple resource IDs. Separate the IDs with commas (,) or enter the IDs on different lines.
Enter Resource IDs
Resource Type
Select a resource type of a service. Example: Instance, Disk, or Snapshot.
Elastic Compute Service:Instance
Resource ID
Enter the IDs of ECS instances in the Resource ID field.
i-bp12d03u8usvakpo****
Click OK.
(Optional) View the associated resources of the tags.
After the tags are created and added, click the icon above the tag list on the Custom Tags tab, find the tags that you added, and then click View Resources in the Actions column that corresponds to each tag. On the page that appears, you can view the resources to which a tag was added.
Remove or delete tags
If you no longer need a tag to manage or retrieve resources, you can remove the tag from the resources. The following section provides an example on how to remove a tag named ECS:Documentation from one or more ECS instances.
Up to 20 tags can be removed at a time.
If you remove a tag from all resources, the tag is automatically deleted.
Log on to the ECS console.
In the left-side navigation pane, click Tags.
On the Custom Tags tab, select Instance from the Resource Type drop-down list.
In the tag list, find the ECS:Documentation tag that you want to remove. Go to the Resources tab by using one of the following methods.
NoteIn the ECS:Documentation tag, the tag key is ECS and the tag value is Documentation.
Method 1: Click the ECS tag key, and then click View Resources in the Actions column corresponding to the Documentation tag value.
Method 2: In the Actions column corresponding to the ECS tag key, click View Resources.
On the Resources tab, remove the tag from one or more resources.
To remove the tag from a single resource, find the resource and click Remove from Resources in the Actions column.
To remove the tag from multiple resources at a time, select the resources and click Remove Current Tag in the lower part of the tab.
In the Remove Current Tag message, click Remove.
After the tag is removed from one or more resources, click the icon on the Resources tab. The resources from which the tag is removed are no longer displayed on the tab.
Best practices for tags
You can use tags to manage resources in a fine-grained manner. Tags are commonly used for the following purposes and to perform the following operations.
Search for or export resources
Use the tag editor to edit the tags of resources and export resource information. For more information, see Tag editor.
Search for resources based on tags by using exact search or fuzzy search. For more information, see Use tags to query cloud resources.
Use tags to control access to resources.
Use tags to grant Resource Access Management (RAM) users access to ECS instances by group. This way, RAM users in different groups can view and manage only specific resources based on tags. For more information, see Use tags to grant access to ECS instances by group.
Specify the tags of ECS instances in custom RAM policies and attach the policies to RAM users. This way, RAM users can view and manage only specific ECS instances based on tags. For more information, see Use tags to enable RAM users to manage only authorized ECS instances.
Automate O&M
Use OOS to batch start multiple ECS instances that have specific tags added. For more information, see Use OOS to start multiple ECS instances with specific tags at a time.
Create an execution by using a public template provided by OOS to enable the disks, ENIs, elastic IP addresses (EIPs), snapshots, and custom images of multiple ECS instances to inherit tags from the ECS instances at a time. For more information, see Use OOS to inherit tags from ECS instances for the resources of the ECS instances at a time.
Create an execution by using a public template provided by OOS to obtain ECS instances to which specific tags are added and add the obtained ECS instances to security groups to which the same tags are added. For more information, see Query ECS instances with a specific tag and add the ECS instances to security groups with the same tag.
Add the same tag to multiple ECS instances, and configure an application group rule in CloudMonitor based on the tag to automatically add instances that have the same tag to a specific application group for automatic monitoring. For more information, see Use tags to enable ECS instances to be automatically added to CloudMonitor application groups.
Batch run multiple Cloud Assistant commands on ECS instances that have specific tags added or upload files by using Cloud Assistant. For more information, see Use tags to control the running of Cloud Assistant commands.
References
You can use resource groups to group your resources based on usage, permissions, and regions. Then, you can manage the resources in a hierarchical manner for various users and projects. For more information, see Resource Group overview or Resource groups.