

# Tagging your ElastiCache resources
<a name="Tagging-Resources"></a>

To help you manage your clusters and other ElastiCache resources, you can assign your own metadata to each resource in the form of tags. Tags enable you to categorize your AWS resources in different ways, for example, by purpose, owner, or environment. This is useful when you have many resources of the same type—you can quickly identify a specific resource based on the tags that you've assigned to it. This topic describes tags and shows you how to create them.

**Warning**  
As a best practice, we recommend that you do not include sensitive data in your tags.

## Tag basics
<a name="Tagging-basics"></a>

A tag is a label that you assign to an AWS resource. Each tag consists of a key and an optional value, both of which you define. Tags enable you to categorize your AWS resources in different ways, for example, by purpose or owner. For example, you could define a set of tags for your account's ElastiCache clusters that helps you track each instance's owner and user group.

We recommend that you devise a set of tag keys that meets your needs for each resource type. Using a consistent set of tag keys makes it easier for you to manage your resources. You can search and filter the resources based on the tags you add. For more information about how to implement an effective resource tagging strategy, see the [AWS whitepaper Tagging Best Practices](https://d1.awsstatic.com/whitepapers/aws-tagging-best-practices.pdf).

Tags don't have any semantic meaning to ElastiCache and are interpreted strictly as a string of characters. Also, tags are not automatically assigned to your resources. You can edit tag keys and values, and you can remove tags from a resource at any time. You can set the value of a tag to `null`. If you add a tag that has the same key as an existing tag on that resource, the new value overwrites the old value. If you delete a resource, any tags for the resource are also deleted. Furthermore, if you add or delete tags on a replication group, all nodes in that replication group will also have their tags added or removed.

 You can work with tags using the AWS Management Console, the AWS CLI, and the ElastiCache API.

If you're using IAM, you can control which users in your AWS account have permission to create, edit, or delete tags. For more information, see [Resource-level permissions](IAM.ResourceLevelPermissions.md).

## Resources you can tag
<a name="Tagging-your-resources"></a>

You can tag most ElastiCache resources that already exist in your account. The table below lists the resources that support tagging. If you're using the AWS Management Console, you can apply tags to resources by using the [Tag Editor](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html). Some resource screens enable you to specify tags for a resource when you create the resource; for example, a tag with a key of Name and a value that you specify. In most cases, the console applies the tags immediately after the resource is created (rather than during resource creation). The console may organize resources according to the **Name** tag, but this tag doesn't have any semantic meaning to the ElastiCache service.

 Additionally, some resource-creating actions enable you to specify tags for a resource when the resource is created. If tags cannot be applied during resource creation, we roll back the resource creation process. This ensures that resources are either created with tags or not created at all, and that no resources are left untagged at any time. By tagging resources at the time of creation, you can eliminate the need to run custom tagging scripts after resource creation. 

 If you're using the Amazon ElastiCache API, the AWS CLI, or an AWS SDK, you can use the `Tags` parameter on the relevant ElastiCache API action to apply tags. They are:
+ `CreateServerlessCache`
+ `CreateCacheCluster`
+ `CreateReplicationGroup`
+ `CopyServerlessCacheSnapshot`
+ `CopySnapshot`
+ `CreateCacheParameterGroup`
+ `CreateCacheSecurityGroup`
+ `CreateCacheSubnetGroup`
+ `CreateServerlessCacheSnapshot`
+ `CreateSnapshot`
+ `CreateUserGroup`
+ `CreateUser`
+ `PurchaseReservedCacheNodesOffering`

The following table describes the ElastiCache resources that can be tagged, and the resources that can be tagged on creation using the ElastiCache API, the AWS CLI, or an AWS SDK.


**Tagging support for ElastiCache resources**  

| Resource | Supports tags | Supports tagging on creation | 
| --- | --- | --- | 
| serverlesscache | Yes | Yes | 
| parametergroup | Yes | Yes | 
| securitygroup | Yes | Yes | 
| subnetgroup | Yes | Yes | 
| replicationgroup | Yes | Yes | 
| cluster | Yes | Yes | 
| reserved-instance | Yes | Yes | 
| serverlesscachesnapshot | Yes | Yes | 
| snapshot | Yes | Yes | 
| user | Yes | Yes | 
| usergroup | Yes | Yes | 

**Note**  
You cannot tag Global Datastores.

You can apply tag-based resource-level permissions in your IAM policies to the ElastiCache API actions that support tagging on creation to implement granular control over the users and groups that can tag resources on creation. Your resources are properly secured from creation—tags that are applied immediately to your resources. Therefore any tag-based resource-level permissions controlling the use of resources are immediately effective. Your resources can be tracked and reported on more accurately. You can enforce the use of tagging on new resources, and control which tag keys and values are set on your resources.

For more information, see [Tagging resources examples](#Tagging-your-resources-example).

 For more information about tagging your resources for billing, see [Monitoring costs with cost allocation tags](Tagging.md).

## Tagging caches and snapshots
<a name="Tagging-replication-groups-snapshots"></a>

The following rules apply to tagging as part of request operations:
+ **CreateReplicationGroup**: 
  + If the `--primary-cluster-id` and `--tags` parameters are included in the request, the request tags will be added to the replication group and propagate to all clusters in the replication group. If the primary cluster has existing tags, these will be overwritten with the request tags to have consistent tags across all nodes.

    If there are no request tags, the primary cluster tags will be added to the replication group and propagated to all clusters.
  + If the `--snapshot-name` or `--serverless-cache-snapshot-name` is supplied:

    If tags are included in the request, the replication group will be tagged only with those tags. If no tags are included in the request, the snapshot tags will be added to the replication group.
  + If the `--global-replication-group-id` is supplied:

    If tags are included in the request, the request tags will be added to the replication group and propagate to all clusters. 
+ **CreateCacheCluster** : 
  +  If the `--replication-group-id` is supplied:

    If tags are included in the request, the cluster will be tagged only with those tags. If no tags are included in the request, the cluster will inherit the replication group tags instead of the primary cluster's tags.
  + If the `--snapshot-name` is supplied:

    If tags are included in the request, the cluster will be tagged only with those tags. If no tags are included in the request, the snapshot tags will be added to the cluster.
+ **CreateServerlessCache** : 
  + If tags are included in the request, only the request tags will be added to the serverless cache.
+ **CreateSnapshot** : 
  +  If the `--replication-group-id` is supplied:

    If tags are included in the request, only the request tags will be added to the snapshot. If no tags are included in the request, the replication group tags will be added to the snapshot. 
  + If the `--cache-cluster-id` is supplied:

    If tags are included in the request, only the request tags will be added to the snapshot. If no tags are included in the request, the cluster tags will be added to the snapshot. 
  + For automatic snapshots:

    Tags will propagate from the replication group tags. 
+ **CreateServerlessCacheSnapshot** : 
  + If tags are included in the request, only the request tags will be added to the serverless cache snapshot.
+ **CopySnapshot** : 
  + If tags are included in the request, only the request tags will be added to the snapshot. If no tags are included in the request, the source snapshot tags will be added to the copied snapshot.
+ **CopyServerlessCacheSnapshot** : 
  + If tags are included in the request, only the request tags will be added to the serverless cache snapshot.
+ **AddTagsToResource** and **RemoveTagsFromResource** : 
  + Tags will be added/removed from the replication group and the action will be propagated to all clusters in the replication group.
**Note**  
**AddTagsToResource** and **RemoveTagsFromResource** cannot be used for default parameter and security groups.
+ **IncreaseReplicaCount** and **ModifyReplicationGroupShardConfiguration**: 
  + All new clusters added to the replication group will have the same tags applied as the replication group. 

## Tag restrictions
<a name="Tagging-restrictions"></a>

The following basic restrictions apply to tags:
+ Maximum number of tags per resource – 50
+ For each resource, each tag key must be unique, and each tag key can have only one value.
+ Maximum key length – 128 Unicode characters in UTF-8.
+ Maximum value length – 256 Unicode characters in UTF-8.
+ Although ElastiCache allows for any character in its tags, other services can be restrictive. The allowed characters across services are: letters, numbers, and spaces representable in UTF-8, and the following characters: \$1 - = . \$1 : / @
+ Tag keys and values are case-sensitive.
+ The `aws:` prefix is reserved for AWS use. If a tag has a tag key with this prefix, then you can't edit or delete the tag's key or value. Tags with the `aws:` prefix do not count against your tags per resource limit.

You can't terminate, stop, or delete a resource based solely on its tags; you must specify the resource identifier. For example, to delete snapshots that you tagged with a tag key called `DeleteMe`, you must use the `DeleteSnapshot` action with the resource identifiers of the snapshots, such as `snap-1234567890abcdef0`.

For more information on ElastiCache resources you can tag, see [Resources you can tag](#Tagging-your-resources).

## Tagging resources examples
<a name="Tagging-your-resources-example"></a>
+ Creating a serverless cache using tags. This example uses Memcached as the engine.

  ```
  aws elasticache create-serverless-cache \
      --serverless-cache-name CacheName \
      --engine memcached
      --tags Key="Cost Center", Value="1110001" Key="project",Value="XYZ"
  ```
+ Adding tags to a serverless cache

  ```
  aws elasticache add-tags-to-resource \
  --resource-name arn:aws:elasticache:us-east-1:111111222233:serverlesscache:my-cache \
  --tags Key="project",Value="XYZ" Key="Elasticache",Value="Service"
  ```
+ Adding tags to a Replication Group.

  ```
  aws elasticache add-tags-to-resource \
  --resource-name arn:aws:elasticache:us-east-1:111111222233:replicationgroup:my-rg \
  --tags Key="project",Value="XYZ" Key="Elasticache",Value="Service"
  ```
+ Creating a Cache Cluster using tags.

  ```
  aws elasticache create-cache-cluster \
  --cluster-id testing-tags \
  --cluster-description cluster-test \
  --cache-subnet-group-name test \
  --cache-node-type cache.t2.micro \
  --engine valkey \
  --tags Key="project",Value="XYZ" Key="Elasticache",Value="Service"
  ```
+ Creating a Cache Cluster using tags. This example uses Redis as the engine.

  ```
  aws elasticache create-cache-cluster \
  --cluster-id testing-tags \
  --cluster-description cluster-test \
  --cache-subnet-group-name test \
  --cache-node-type cache.t2.micro \
  --engine valkey \
  --tags Key="project",Value="XYZ" Key="Elasticache",Value="Service"
  ```
+ Creating a serverless snapshot with tags. This example uses Memcached as the engine.

  ```
  aws elasticache create-serverless-cache-snapshot \
  --serverless-cache-name testing-tags \
  --serverless-cache-snapshot-name bkp-testing-tags-scs \
  --tags Key="work",Value="foo"
  ```
+ Creating a Snapshot with tags.

  Snapshots are currently only available for Redis. For this case, if you add tags on request, even if the replication group contains tags, the snapshot will receive only the request tags. 

  ```
  aws elasticache create-snapshot \
  --replication-group-id testing-tags \
  --snapshot-name bkp-testing-tags-rg \
  --tags Key="work",Value="foo"
  ```

## Tag-Based access control policy examples
<a name="Tagging-access-control"></a>

1. Allowing `AddTagsToResource` action to a cluster only if the cluster has the tag Project=XYZ.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "elasticache:AddTagsToResource",
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceTag/Project": "XYZ"
                   }
               }
           }
       ]
   }
   ```

------

1. Allowing to `RemoveTagsFromResource` action from a replication group if it contains the tags Project and Service and keys are different from Project and Service.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "elasticache:RemoveTagsFromResource",
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceTag/Service": "Elasticache",
                       "aws:ResourceTag/Project": "XYZ"
                   },                
                   "ForAnyValue:StringNotEqualsIgnoreCase": {
                       "aws:TagKeys": [
                           "Project",
                           "Service"
                       ]
                   }
               }
           }
       ]
   }
   ```

------

1. Allowing `AddTagsToResource` to any resource only if tags are different from Project and Service.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": "elasticache:AddTagsToResource",
               "Resource": [
                   "arn:aws:elasticache:*:*:*:*"
               ],
               "Condition": {
                   "ForAnyValue:StringNotEqualsIgnoreCase": {
                       "aws:TagKeys": [ 
                           "Service", 
                           "Project" 
                       ]
                   }
               }
           }
       ]
   }
   ```

------

1. Denying `CreateReplicationGroup` action if request has `Tag Project=Foo`.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Deny",
               "Action": "elasticache:CreateReplicationGroup",
               "Resource": [
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:RequestTag/Project": "Foo"
                   }
               }
           }
       ]
   }
   ```

------

1. Denying `CopySnapshot` action if source snapshot has tag Project=XYZ and request tag is Service=Elasticache.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Deny",
               "Action": "elasticache:CopySnapshot",
               "Resource": [
                   "arn:aws:elasticache:*:*:snapshot:*"
               ],
               "Condition": {
                   "StringEquals": {
                       "aws:ResourceTag/Project": "XYZ",
                       "aws:RequestTag/Service": "Elasticache"
                   }
               }
           }
       ]
   }
   ```

------

1. Denying `CreateCacheCluster` action if the request tag `Project` is missing or is not equal to `Dev`, `QA` or `Prod`.

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
             {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:parametergroup:*",
                   "arn:aws:elasticache:*:*:subnetgroup:*",
                   "arn:aws:elasticache:*:*:securitygroup:*",
                   "arn:aws:elasticache:*:*:replicationgroup:*"
               ]
           },
           {
               "Effect": "Deny",
               "Action": [
                   "elasticache:CreateCacheCluster"
               ],
               "Resource": [
                   "arn:aws:elasticache:*:*:cluster:*"
               ],
               "Condition": {
                   "Null": {
                       "aws:RequestTag/Project": "true"
                   }
               }
           },
           {
               "Effect": "Allow",
               "Action": [
                   "elasticache:CreateCacheCluster",
                   "elasticache:AddTagsToResource"
               ],
               "Resource": "arn:aws:elasticache:*:*:cluster:*",
               "Condition": {
                   "StringEquals": {
                       "aws:RequestTag/Project": [
                           "Dev",
                           "Prod",
                           "QA"
                       ]
                   }
               }
           }
       ]
   }
   ```

------

For related information on condition keys, see [Using condition keys](IAM.ConditionKeys.md).

# Monitoring costs with cost allocation tags
<a name="Tagging"></a>

When you add cost allocation tags to your resources in Amazon ElastiCache, you can track costs by grouping expenses on your invoices by resource tag values.

An ElastiCache cost allocation tag is a key-value pair that you define and associate with an ElastiCache resource. The key and value are case-sensitive. You can use a tag key to define a category, and the tag value can be an item in that category. For example, you might define a tag key of `CostCenter` and a tag value of `10010`, indicating that the resource is assigned to the 10010 cost center. You can also use tags to designate resources as being used for test or production by using a key such as `Environment` and values such as `test` or `production`. We recommend that you use a consistent set of tag keys to make it easier to track costs associated with your resources.

Use cost allocation tags to organize your AWS bill to reflect your own cost structure. To do this, sign up to get your AWS account bill with tag key values included. Then, to see the cost of combined resources, organize your billing information according to resources with the same tag key values. For example, you can tag several resources with a specific application name, and then organize your billing information to see the total cost of that application across several services. 

You can also combine tags to track costs at a greater level of detail. For example, to track your service costs by region you might use the tag keys `Service` and `Region`. On one resource you might have the values `ElastiCache` and `Asia Pacific (Singapore)`, and on another resource the values `ElastiCache` and `Europe (Frankfurt)`. You can then see your total ElastiCache costs broken out by region. For more information, see [Use Cost Allocation Tags](https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/cost-alloc-tags.html) in the *AWS Billing User Guide*.

You can add ElastiCache cost allocation tags to ElastiCache node-based clusters. When you add, list, modify, copy, or remove a tag, the operation is applied only to the specified cluster.

**Characteristics of ElastiCache cost allocation tags**
+ Cost allocation tags are applied to ElastiCache resources which are specified in CLI and API operations as an ARN. The resource-type will be a "cluster".

  Sample ARN: `arn:aws:elasticache:<region>:<customer-id>:<resource-type>:<resource-name>`

  Sample arn: `arn:aws:elasticache:us-west-2:1234567890:cluster:my-cluster`
+ The tag key is the required name of the tag. The key's string value can be from 1 to 128 Unicode characters long and cannot be prefixed with `aws:`. The string can contain only the set of Unicode letters, digits, blank spaces, underscores ( \$1 ), periods ( . ), colons ( : ), backslashes ( \$1 ), equal signs ( = ), plus signs ( \$1 ), hyphens ( - ), or at signs ( @ ).

   
+ The tag value is the optional value of the tag. The value's string value can be from 1 to 256 Unicode characters in length and cannot be prefixed with `aws:`. The string can contain only the set of Unicode letters, digits, blank spaces, underscores ( \$1 ), periods ( . ), colons ( : ), backslashes ( \$1 ), equal signs ( = ), plus signs ( \$1 ), hyphens ( - ), or at signs ( @ ).

   
+ An ElastiCache resource can have a maximum of 50 tags.

   
+ Values do not have to be unique in a tag set. For example, you can have a tag set where the keys `Service` and `Application` both have the value `ElastiCache`.

AWS does not apply any semantic meaning to your tags. Tags are interpreted strictly as character strings. AWS does not automatically set any tags on any ElastiCache resource.

# Managing your cost allocation tags using the AWS CLI
<a name="Tagging.Managing.CLI"></a>

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

Cost allocation tags are applied to ElastiCache clusters. The cluster to be tagged is specified using an ARN (Amazon Resource Name).

Sample arn: `arn:aws:elasticache:us-west-2:1234567890:cluster:my-cluster`

**Topics**
+ [Listing tags using the AWS CLI](#Tagging.Managing.CLI.List)
+ [Adding tags using the AWS CLI](#Tagging.Managing.CLI.Add)
+ [Modifying tags using the AWS CLI](#Tagging.Managing.CLI.Modify)
+ [Removing tags using the AWS CLI](#Tagging.Managing.CLI.Remove)

## Listing tags using the AWS CLI
<a name="Tagging.Managing.CLI.List"></a>

You can use the AWS CLI to list tags on an existing ElastiCache resource by using the [list-tags-for-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/list-tags-for-resource.html) operation.

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

For Linux, macOS, or Unix:

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

For Windows:

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

The following code uses the AWS CLI to list the tags on the Valkey or Redis OSS node `my-cluster-001` in the `my-cluster` cluster in region us-west-2.

For Linux, macOS, or Unix:

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

For Windows:

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

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

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

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

```
{
   "TagList": []
}
```

For more information, see the AWS CLI for ElastiCache [list-tags-for-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/list-tags-for-resource.html).

## Adding tags using the AWS CLI
<a name="Tagging.Managing.CLI.Add"></a>

You can use the AWS CLI to add tags to an existing ElastiCache resource by using the [add-tags-to-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/add-tags-to-resource.html) 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 node `my-cluster-001` in the cluster `my-cluster` in region us-west-2.

**Memcached**

For Linux, macOS, or 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
```

For 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**

For Linux, macOS, or 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
```

For 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
```

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

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

For more information, see the AWS CLI for ElastiCache [add-tags-to-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/add-tags-to-resource.html).

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](https://docs.aws.amazon.com/cli/latest/reference/elasticache/create-cache-cluster.html). You cannot add tags when creating a cluster using the ElastiCache management console. After the cluster is created, you can then use the console to add tags to the cluster.

## Modifying tags using the AWS CLI
<a name="Tagging.Managing.CLI.Modify"></a>

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

To modify tags:
+ Use [add-tags-to-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/add-tags-to-resource.html) to either add a new tag and value or to change the value associated with an existing tag.
+ Use [remove-tags-from-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/remove-tags-from-resource.html) to remove specified tags from the resource.

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

## Removing tags using the AWS CLI
<a name="Tagging.Managing.CLI.Remove"></a>

You can use the AWS CLI to remove tags from an existing ElastiCache for Memcached cluster by using the [remove-tags-from-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/remove-tags-from-resource.html) operation.

For Memcached, the following code uses the AWS CLI to remove the tags with the keys `Service` and `Region` from the node `my-cluster-001` in  the cluster `my-cluster` in the us-west-2 region.

For Linux, macOS, or Unix:

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

For Windows:

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

For Redis OSS, the following code uses the AWS CLI to remove the tags with the keys `Service` and `Region` from the node `my-cluster-001` in the cluster `my-cluster` in the us-west-2 region.

For Linux, macOS, or Unix:

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

For Windows:

```
aws elasticache remove-tags-from-resource ^
 --resource-name arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001 ^
 --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.

```
{
   "TagList": []
}
```

For more information, see the AWS CLI for ElastiCache [remove-tags-from-resource](https://docs.aws.amazon.com/cli/latest/reference/elasticache/remove-tags-from-resource.html).

# Managing your cost allocation tags using the ElastiCache API
<a name="Tagging.Managing.API"></a>

You can use the ElastiCache API to add, modify, or remove cost allocation tags.

Cost allocation tags are applied to ElastiCache for Memcached clusters. The cluster to be tagged is specified using an ARN (Amazon Resource Name).

Sample arn: `arn:aws:elasticache:us-west-2:1234567890:cluster:my-cluster`

**Topics**
+ [Listing tags using the ElastiCache API](#Tagging.Managing.API.List)
+ [Adding tags using the ElastiCache API](#Tagging.Managing.API.Add)
+ [Modifying tags using the ElastiCache API](#Tagging.Managing.API.Modify)
+ [Removing tags using the ElastiCache API](#Tagging.Managing.API.Remove)

## Listing tags using the ElastiCache API
<a name="Tagging.Managing.API.List"></a>

You can use the ElastiCache API to list tags on an existing resource by using the [ListTagsForResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_ListTagsForResource.html) operation.

For Memcached, the following code uses the ElastiCache API to list the tags on the resource `my-cluster` in the us-west-2 region.

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=ListTagsForResource
   &ResourceName=arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Version=2015-02-02
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```

For Redis OSS, the following code uses the ElastiCache API to list the tags on the resource `my-cluster-001` in the us-west-2 region.

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=ListTagsForResource
   &ResourceName=arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Version=2015-02-02
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```

## Adding tags using the ElastiCache API
<a name="Tagging.Managing.API.Add"></a>

You can use the ElastiCache API to add tags to an existing ElastiCache cluster by using the [AddTagsToResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_AddTagsToResource.html) 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 ElastiCache API to add the keys `Service` and `Region` with the values `elasticache` and `us-west-2` respectively. For Memcached, this is applied to the resource `my-cluster`. For Redis OSS, this is applied to the resource `my-cluster-001` in the us-west-2 region. 

**Memcached**

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=AddTagsToResource
   &ResourceName=arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Tags.member.1.Key=Service 
   &Tags.member.1.Value=elasticache
   &Tags.member.2.Key=Region
   &Tags.member.2.Value=us-west-2
   &Version=2015-02-02
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```

**Redis**

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=AddTagsToResource
   &ResourceName=arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Tags.member.1.Key=Service 
   &Tags.member.1.Value=elasticache
   &Tags.member.2.Key=Region
   &Tags.member.2.Value=us-west-2
   &Version=2015-02-02
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```

For more information, see [AddTagsToResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_AddTagsToResource.html) in the *Amazon ElastiCache API Reference*.

## Modifying tags using the ElastiCache API
<a name="Tagging.Managing.API.Modify"></a>

You can use the ElastiCache API to modify the tags on an ElastiCache cluster.

To modify the value of a tag:
+ Use [AddTagsToResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_AddTagsToResource.html) operation to either add a new tag and value or to change the value of an existing tag.
+ Use [RemoveTagsFromResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_RemoveTagsFromResource.html) to remove tags from the resource.

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

Use [RemoveTagsFromResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_RemoveTagsFromResource.html) to remove tags from the resource.

## Removing tags using the ElastiCache API
<a name="Tagging.Managing.API.Remove"></a>

You can use the ElastiCache API to remove tags from an existing ElastiCache for Memcached cluster by using the [RemoveTagsFromResource](https://docs.aws.amazon.com/AmazonElastiCache/latest/APIReference/API_RemoveTagsFromResource.html) operation.

The following code uses the ElastiCache API to remove the tags with the keys `Service` and `Region` from the node `my-cluster-001` in the  cluster `my-cluster` in region us-west-2.

```
https://elasticache.us-west-2.amazonaws.com/
   ?Action=RemoveTagsFromResource
   &ResourceName=arn:aws:elasticache:us-west-2:0123456789:cluster:my-cluster-001
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &TagKeys.member.1=Service
   &TagKeys.member.2=Region
   &Version=2015-02-02
   &Timestamp=20150202T192317Z
   &X-Amz-Credential=<credential>
```