本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用管理您的成本分配标签 Amazon CLI
您可以使用 Amazon CLI 添加、修改或移除成本分配标签。
成本分配标签适用于集 ElastiCache 群。要标记的集群是使用ARN(Amazon 资源名称)指定的。
示例 arn:arn:aws:elasticache:us-west-2:1234567890:cluster:my-cluster
使用列出标签 Amazon CLI
您可以使用列 Amazon CLI 出现有 ElastiCache 资源的标签,方法是 list-tags-for-resource 操作。
以下代码使用列出 us-west-2 区域的 Memcached 集群my-cluster
上的标签。 Amazon CLI
对于 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
以下代码使用列出 us- Amazon CLI west-2 区域my-cluster
集群my-cluster-001
中 Valkey 或 Redis OSS 节点上的标签。
对于 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。
{
"TagList": []
}
有关更多信息, Amazon CLI 请参阅 ElastiCache list-tags-for-resource.
使用添加标签 Amazon CLI
您可以使用 Amazon CLI 向现有 ElastiCache 资源添加标签,方法是 add-tags-to-resource CLI操作。如果资源上不存在标签键,则键和值将添加到资源。如果资源上已存在该键,则与该键关联的值将更新为新值。
以下代码使用将密钥Service
elasticache
和Region
值us-west-2
分别添加 Amazon CLI 到 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"
}
]
}
有关更多信息, Amazon CLI 请参阅 ElastiCache add-tags-to-resource.
在 Amazon CLI 使用操作创建新集群时,也可以使用向集群添加标签 create-cache-cluster。 使用 ElastiCache 管理控制台创建集群时,您无法添加标签。创建集群之后,随后可以使用控制台向集群添加标签。
使用修改标签 Amazon CLI
您可以使用 Amazon CLI 来修改 ElastiCache 集群上的标签。
修改标签:
-
使用 add-tags-to-resource 要么添加新标签和值,要么更改与现有标签关联的值。
-
使用 remove-tags-from-resource 从资源中移除指定的标签。
以上任意操作的输出将是指定集群上标签及其值的列表。
使用移除标签 Amazon CLI
您可以使用从现有 ElastiCache 的 Amazon CLI Memcached 集群中移除标签,方法是 remove-tags-from-resource 操作。
对于 Memcached,以下代码使用Region
从集群中位于 us-west-2 区域my-cluster-001
的节点上删除带有密钥Service
my-cluster
的标签。 Amazon CLI
对于 Linux、macOS 或 Unix:
aws elasticache remove-tags-from-resource \ --resource-name arn:aws:elasticache:
us-west-2:0123456789:cluster:my-cluster
\ --tag-keysPM Service
对于 Windows:
aws elasticache remove-tags-from-resource ^ --resource-name arn:aws:elasticache:
us-west-2:0123456789:cluster:my-cluster
^ --tag-keysPM Service
对于 RedisOSS,以下代码使用Region
从集群中位于 us-west-2 区域my-cluster-001
的节点上删除带有密钥Service
my-cluster
的标签。 Amazon CLI
对于 Linux、macOS 或 Unix:
aws elasticache remove-tags-from-resource \ --resource-name arn:aws:elasticache:
us-west-2:0123456789:cluster:my-cluster-001
\ --tag-keysPM Service
对于 Windows:
aws elasticache remove-tags-from-resource ^ --resource-name arn:aws:elasticache:
us-west-2:0123456789:cluster:my-cluster-001
^ --tag-keysPM Service
此操作的输出将类似于下文,先列出资源上的所有标签,后面跟随操作。
{
"TagList": []
}
有关更多信息, Amazon CLI 请参阅 ElastiCache remove-tags-from-resource.