使用 管理您的成本分配標籤 AWS CLI - Amazon ElastiCache

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 管理您的成本分配標籤 AWS CLI

您可以使用 AWS CLI 新增、修改或移除成本分配標籤。

成本分配標籤會套用至 ElastiCache 叢集。要加標籤的叢集是使用 ARN (Amazon Resource Name) 來指定。

範例 ARN:arn:aws:elasticache:us-west-2:1234567890:cluster:my-cluster

使用 列出標籤 AWS CLI

您可以使用 AWS CLI 來列出現有 ElastiCache 資源上的標籤,方法是使用 list-tags-for-resource操作。

下列程式碼使用 AWS CLI 列出 us-west-2 my-cluster 區域中 Memcached 叢集上的標籤。

若為 Linux、macOS 或 Unix:

aws elasticache list-tags-for-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster

針對 Windows:

aws elasticache list-tags-for-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster

下列程式碼使用 AWS CLI 列出在 us-west-2 區域中my-cluster叢集中 Valkey 或 Redis OSS 節點my-cluster-001上的標籤。

若為 Linux、macOS 或 Unix:

aws elasticache list-tags-for-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001

針對 Windows:

aws elasticache list-tags-for-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001

此操作的輸出看起來應該類似以下,這是資源上所有標籤的清單。

{ "TagList": [ { "Value": "10110", "Key": "CostCenter" }, { "Value": "EC2", "Key": "Service" } ] }

如果資源上沒有標籤,輸出會是空的標籤清單。

{ "TagList": [] }

如需詳細資訊,請參閱適用於 ElastiCache AWS CLI 的 list-tags-for-resource。

使用 新增標籤 AWS CLI

您可以使用 使用 CLI add-tags-to-resource 操作 AWS CLI ,將標籤新增至現有的 ElastiCache 資源。如果標籤索引鍵不存在於資源上,則索引鍵和值會新增至資源。如果索引鍵已存在於資源上,則與該索引鍵相關聯的值會更新為新的值。

下列程式碼使用 AWS CLI 將索引鍵 ServiceRegion與值 elasticacheus-west-2分別新增至 us-west-2 區域中my-cluster-001叢集中的節點my-cluster

Memcached

若為 Linux、macOS 或 Unix:

aws elasticache add-tags-to-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster \ --tags Key=Service,Value=elasticache \ Key=Region,Value=us-west-2

針對 Windows:

aws elasticache add-tags-to-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster ^ --tags Key=Service,Value=elasticache ^ Key=Region,Value=us-west-2

Redis

若為 Linux、macOS 或 Unix:

aws elasticache add-tags-to-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001 \ --tags Key=Service,Value=elasticache \ Key=Region,Value=us-west-2

針對 Windows:

aws elasticache add-tags-to-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001 ^ --tags Key=Service,Value=elasticache ^ Key=Region,Value=us-west-2

此操作的輸出看起來應該類似以下,這是在操作後資源上所有標籤的清單。

{ "TagList": [ { "Value": "elasticache", "Key": "Service" }, { "Value": "us-west-2", "Key": "Region" } ] }

如需詳細資訊,請參閱適用於 ElastiCache AWS CLI 的 add-tags-to-resource。

當您使用 操作 建立新叢集時 AWS CLI ,您也可以使用 將標籤新增至叢集create-cache-cluster。使用 ElastiCache 管理主控台建立叢集時無法新增標籤。建立叢集之後,您可以接著使用主控台來將標籤新增至叢集。

使用 修改標籤 AWS CLI

您可以使用 AWS CLI 來修改 ElastiCache 叢集上的標籤。

若要修改標籤:

  • 使用 add-tags-to-resource 來新增標籤和值,或是變更與現有標籤關聯的值。

  • 使用 remove-tags-from-resource 來從資源移除指定的標籤。

這兩項操作的輸出會是指定叢集上標籤和其值的清單。

使用 移除標籤 AWS CLI

您可以使用 AWS CLI 操作,從現有的 ElastiCache for Memcached 叢集中移除標籤remove-tags-from-resource。

對於 Memcached,下列程式碼使用 AWS CLI 來移除具有金鑰的標籤,Service以及Region從 us-west-2 my-cluster 區域中叢集my-cluster-001中的節點移除標籤。

若為 Linux、macOS 或 Unix:

aws elasticache remove-tags-from-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster \ --tag-keys PM Service

針對 Windows:

aws elasticache remove-tags-from-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster ^ --tag-keys PM Service

對於 Redis OSS,下列程式碼使用 AWS CLI 來移除具有金鑰的標籤,Service以及Region從 us-west-2 my-cluster 區域中叢集my-cluster-001中的節點移除標籤。

若為 Linux、macOS 或 Unix:

aws elasticache remove-tags-from-resource \ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001 \ --tag-keys PM Service

針對 Windows:

aws elasticache remove-tags-from-resource ^ --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001 ^ --tag-keys PM Service

此操作的輸出看起來應該類似以下,這是在操作後資源上所有標籤的清單。

{ "TagList": [] }

如需詳細資訊,請參閱適用於 ElastiCache AWS CLI 的 remove-tags-from-resource。