Menu
Amazon ElastiCache
User Guide (API Version 2015-02-02)

Managing Your Cost Allocation Tags Using the AWS CLI

You can use the AWS CLI to add, modify, or remove cost allocation tags.

Cost allocation tags are applied to ElastiCache resources. What that resource is and how it is specified in an ARN depends on the engine and structure of the cluster.

  • Memcached: Tags are applied to clusters.

    Sample arn: arn:aws:elasticache:us-west-2:1234567890:cluster:mymemcached

  • Redis: Tags are applied to individual nodes. Because of this, nodes in Redis clusters with replication can have different tags.

    Sample arns

    • Redis (cluster mode disabled) no replication:

      Sample arn: arn:aws:elasticache:us-west-2:1234567890:cluster:myredis

    • Redis (cluster mode disabled) with replication:

      Sample arn: arn:aws:elasticache:us-west-2:1234567890:cluster:myredis-001

    • Redis (cluster mode enabled):

      Sample arn: arn:aws:elasticache:us-west-2:1234567890:cluster:myredis-0001-001

  • Backups (Redis): Tags are applied to the backup.

    Sample arn: arn:aws:elasticache:us-west-2:1234567890:snapshot:myredisbackup

Listing Tags Using the AWS CLI

You can use the AWS CLI to list tags on an existing ElastiCache resource by using the list-tags-for-resource operation.

The following code uses the AWS CLI to list the tags on the Memcached cluster myCluster in the us-west-2 region.

For Linux, macOS, or Unix:

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

For Windows:

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

Output from this operation will look something like the following, a list of all the tags on the resource.

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

If there are no tags on the resource, the output will be an empty TagList.

Copy
{ "TagList": [] }

For more information, see the AWS CLI for ElastiCache list-tags-for-resource.

Adding Tags Using the AWS CLI

You can use the AWS CLI to add tags to an existing ElastiCache resource by using the add-tags-to-resource CLI operation. If the tag key does not exist on the resource, the key and value are added to the resource. If the key already exists on the resource, the value associated with that key is updated to the new value.

The following code uses the AWS CLI to add the keys Service and Region with the values elasticache and us-west-2 respectively to the resource myCluster in the us-west-2 region.

For Linux, macOS, or Unix:

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

For Windows:

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

Output from this operation will look something like the following, a list of all the tags on the resource following the operation.

Copy
{ "TagList": [ { "Value": "10110", "Key": "CostCenter" }, { "Value": "EC2", "Key": "Service" }, { "Value": "", "Key": "PM" }, { "Value": "us-west-2", "Key": "Region" } ] }

For more information, see the AWS CLI for ElastiCache add-tags-to-resource.

You can also use the AWS CLI to add tags to a cluster when you create a new cluster by using the operation create-cache-cluster, or when you create a new replication group by using the operation create-replication-group. Note that you cannot add tags during resource creation with the ElastiCache management console. After the cluster or replication group is created, you can then use the console to add tags to the resource.

Modifying Tags Using the AWS CLI

You can use the AWS CLI to modify the tags on an ElastiCache resource.

To modify the value of a tag:

Output from either operation will be a list of tags and their values on the specified resource.

Removing Tags Using the AWS CLI

You can use the AWS CLI to remove tags from an existing ElastiCache resource by using the remove-tags-from-resource operation.

The following code uses the AWS CLI to remove the tags with the keys Service and Region from the resource myCluster in the us-west-2 region.

For Linux, macOS, or Unix:

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

For Windows:

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

Output from this operation will look something like the following, a list of all the tags on the resource following the operation.

Copy
{ "TagList": [ { "Value": "10110", "Key": "CostCenter" }, { "Value": "us-west-2", "Key": "Region" } ] }

For more information, see the AWS CLI for ElastiCache remove-tags-from-resource.