Use tags to classify and manage ECS resources

更新时间:
复制 MD 格式

As your cloud footprint expands, managing your resources becomes more complex. You might find it difficult to track costs or monitor resources in bulk. Tags help you classify resources for fine-grained management. By attaching tags, you can organize resources across various dimensions, such as by owner, purpose, or environment.

For more information, see What is a tag.

Use cases

As your number of ECS instances grows, tagging them makes it easier to perform searches and bulk operations. Common use cases for tags include:

  • Manage application deployment workflows

  • Track resources and manage them in groups based on tags

  • Automate group-based operations by using tags with services such as CloudOps Orchestration Service, Resource Orchestration Service (ROS), Auto Scaling, and Cloud Assistant

  • Manage costs and allocate expenses based on tags

  • Design resource-based or role-based access control

This topic describes the following two use cases in detail. For more use cases, see What is a tag.

Use case 1: Resource management and automation

You can bind different tags for various dimensions, such as environment (production or test), operating system (Windows or Linux), or client platform (iOS or Android). For example, you can bind a key-value pair such as Test:Server-Windows to all ECS instances in your test environment. This lets you quickly filter for these instances during maintenance.标签应用场景示例二

Examples of bulk operations:

Use case 2: Team and project management

For team or project management, you can add tags that represent dimensions such as groups, projects, or departments, for example, CostCenter:aliyun. You can then use these tags to group resources, manage cost allocation in the Expenses and Costs console, or configure cross-account access.标签应用场景示例

For more information, see the following topics:

Usage notes

Each tag is a key-value pair. For any given resource, each tag key must be unique.

Important

Before you use tags, you must understand their limits and quotas. For more information, see What is a tag.

ECS resources that support tags

  • ECS instance

  • Cloud disk

  • Reserved instance

  • Block storage

  • Snapshot

  • Snapshot consistency group

  • Automatic snapshot policy

  • Image

  • Image component

  • Image template

  • Security group

  • Elastic network interface (ENI)

  • Dedicated host

  • SSH key pair

  • Launch template

  • Dedicated host group

  • Elasticity Assurance

  • Capacity reservation

  • Storage Capacity Unit (SCU)

  • Cloud Assistant command

  • Cloud Assistant command execution or file delivery result

  • Cloud Assistant managed instance

  • Activation code for a Cloud Assistant managed instance

Create and bind tags

Before you create tags, see Tag design principles for background information and examples. Follow these steps to create and bind a tag:

Important

You can bind a maximum of 20 tags to a single resource. If a resource already has 20 tags, you must unbind some tags before you can bind new ones.

  1. Go to ECS console - Tags.

  2. In the upper-left corner of the page, select a region and resource group.地域

  3. On the Custom Tags tab, click Create Custom Tag.

  4. On the Create Custom Tag page, perform the following steps.

    When you create a custom tag, you must also bind it to a resource. If you want to create a tag without immediately binding it to a resource, use a preset tag. For more information, see Create a tag.

    1. Create a new tag.

      tag

      The following table describes the parameters.

      Parameter

      Required

      Description

      Tag Key

      Yes

      Enter a new tag key or select an existing one.

      • A new tag key can be up to 128 characters long. It cannot start with aliyun or acs:, nor can it contain http:// or https://.

      • When you select an existing tag key, fuzzy search is supported.

      Value

      No

      Enter a tag value.

      The tag value can be up to 128 characters in length and cannot contain http:// or https://.

      Note

      You can create multiple tags that have the same tag key but different tag values. To do this, select an existing tag key and enter a new tag value.

    2. Click Next.

    3. Configure the parameters to bind the tag to resources.

      The following table describes the parameters.

      Parameter

      Description

      Example

      Method for Specifying Resources

      You can specify resources in one of the following ways:

      • Select from Resource List: Select one or more resources from the list.

      • Enter Resource IDs: Enter the resource IDs in the Search by resource ID text box.

        Note
        • Separate multiple resource IDs with commas (,) or line breaks.

        • You can bind a maximum of 20 tags in a single operation.

      Enter Resource IDs

      Service

      Select the resource type. For example, for ECS, you can select Instance, cloud disk, or snapshot.

      Elastic Compute Service:Instance

      Search by resource ID

      Enter the ID of the ECS instance.

      i-bp12d03u8usvakpo****

    4. Click OK.

    5. Optional: View the bound resources.

      After the tag is created and bound, click the tag1 icon above the tag list on the Custom Tags tab. Find the tag and click View Resources in the Actions column.

      check resource

Unbind or delete tags

If a tag is no longer needed, you can unbind it from resources. This section uses the following example to show how to unbind a tag: unbinding the ECS:Documentation tag (tag key: ECS, tag value: Documentation) from an Elastic Compute Service:Instance resource.

Important
  • You can unbind a maximum of 20 tags at a time.

  • After you unbind a tag from all its associated resources, the system automatically deletes the tag within 24 hours.

  1. On the Custom Tags tab, select Instance from the resource type drop-down list.

  2. In the tag list, find the ECS:Documentation tag that you want to unbind. Go to the Resources page by using one of the following methods:

    • Method 1: Click the ECS tag key. In the row for the Documentation tag value, click View Resources in the Actions column.

    • Method 2: In the row for the ECS tag key, click View Resources in the Actions column.

  3. On the Resources tab, unbind the tag from one or more resources.

    • To unbind the tag from a single resource: Find the resource and click Disassociate from Resource in the Actions column.

    • To unbind the tag from multiple resources: Select the resources and then click Unbind Current Tag or Unbind Tags.

    remove resources

  4. In the Disassociate from Resource dialog box, click OK.

    After the tag is unbound, click the tag1.png icon on the Resources page. You can verify that the tag has been unbound from the resource.

Tagging best practices

Common uses include:

Related topics

  • You can also use resource groups to group your cloud resources based on dimensions such as purpose, permissions, and ownership. This allows for hierarchical management of resources for multiple users and projects within an enterprise. For more information, see What is a resource group? or Resource groups.

  • Call the TagResources API operation to create and bind tags.

  • Call the ListTagResources API operation to query the tags that are bound to a resource.

  • Call the UntagResources API operation to unbind tags from specified resources.

  • Call the JoinResourceGroup API operation to add an ECS resource or service to a resource group.