

# Tagging your MemoryDB resources
<a name="tagging-resources"></a>

To help you manage your clusters and other MemoryDB 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 MemoryDB clusters that helps you track each cluster'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 MemoryDB 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.

 You can work with tags using the AWS Management Console, the AWS CLI, and the MemoryDB 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 MemoryDB 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 MemoryDB 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 MemoryDB API, the AWS CLI, or an AWS SDK, you can use the `Tags` parameter on the relevant MemoryDB API action to apply tags. They are:
+ `CreateCluster`
+ `CopySnapshot`
+ `CreateParameterGroup`
+ `CreateSubnetGroup`
+ `CreateSnapshot`
+ `CreateACL`
+ `CreateUser`
+ `CreateMultiRegionCluster`

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


**Tagging support for MemoryDB resources**  

| Resource | Supports tags | Supports tagging on creation | 
| --- | --- | --- | 
| parametergroup | Yes | Yes | 
| subnetgroup | Yes | Yes | 
| cluster | Yes | Yes | 
| snapshot | Yes | Yes | 
| user | Yes | Yes | 
| acl | Yes | Yes | 
| multiregioncluster | Yes | Yes | 

You can apply tag-based resource-level permissions in your IAM policies to the MemoryDB 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 clusters and snapshots, and Multi-Region clusters
<a name="tagging-clusters-snapshots"></a>

The following rules apply to tagging as part of request operations:
+ **CreateCluster** : 
  +  If the `--cluster-name` is supplied:

    If tags are included in the request, the cluster will be tagged.
  + 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.
+ **CreateSnapshot** : 
  +  If the `--cluster-name` 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 cluster tags. 
+ **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.
+ **TagResource** and **UntagResource** : 

  Tags will be added/removed from the resource.

## Tagging Multi Region clusters
<a name="tagging-multi-region-clusters"></a>

MemoryDB multi megion clusters are a global resource. As such, tags can be specified, modified or listed on multi region clusters by invoking the relevant APIs in any given region where MemoryDB Multi-Region is supported. For more information on region support, see [Prerequisites and limitations](multi-region.prereq.md).

Tags on multi region clusters are independent from tags on regional clusters. You can specify different sets of tags on a multi region cluster and it’s contained regional clusters. There is no hierarchical connection between these tags and they are not copied through the hierarchy between these resource types.

When you add or remove tags through the `TagResource` and `UntagResource` APIs, you might not immediately see the latest effective tags in the ListTags API response, due to the tags being eventually consistent specifically for Multi Region clusters.

## 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 MemoryDB 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 MemoryDB resources you can tag, see [Resources you can tag](#tagging-your-resources).

## Tagging resources examples
<a name="tagging-your-resources-example"></a>
+ Adding tags to a cluster.

  ```
  aws memorydb tag-resource \
  --resource-arn arn:aws:memorydb:us-east-1:111111222233:cluster/my-cluster \
  --tags Key="project",Value="XYZ" Key="memorydb",Value="Service"
  ```
+ Creating a cluster using tags.

  ```
  aws memorydb create-cluster \
  --cluster-name testing-tags \
  --description cluster-test \
  --subnet-group-name test \
  --node-type db.r6g.large \
  --acl-name open-access \
  --tags Key="project",Value="XYZ" Key="memorydb",Value="Service"
  ```
+ Creating a Snapshot with tags.

  For this case, if you add tags on request, even if the cluster contains tags, the snapshot will receive only the request tags. 

  ```
  aws memorydb create-snapshot \
  --cluster-name testing-tags \
  --snapshot-name bkp-testing-tags-mycluster \
  --tags Key="work",Value="foo"
  ```

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

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

A MemoryDB cost allocation tag is a key-value pair that you define and associate with a MemoryDB 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 `MemoryDB` and `Asia Pacific (Singapore)`, and on another resource the values `MemoryDB` and `Europe (Frankfurt)`. You can then see your total MemoryDB 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 MemoryDB cost allocation tags to MemoryDB clusters. When you add, list, modify, copy, or remove a tag, the operation is applied only to the specified cluster.

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

  ARN Format: `arn:aws:memorydb:<region>:<customer-id>:<resource-type>/<resource-name>`

  Sample ARN: `arn:aws:memorydb:us-east-1: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 ( @ ).
+ A MemoryDB 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 `MemoryDB`.

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 MemoryDB 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.

Sample arn: `arn:aws:memorydb:us-east-1: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 MemoryDB resource by using the [list-tags](https://docs.aws.amazon.com/cli/latest/reference/memorydb/list-tags.html) operation.

The following code uses the AWS CLI to list the tags on the MemoryDB cluster `my-cluster` in region us-east-1.

For Linux, macOS, or Unix:

```
aws memorydb list-tags \
  --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster
```

For Windows:

```
aws memorydb list-tags ^
  --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster
```

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 MemoryDB [list-tags](https://docs.aws.amazon.com/cli/latest/reference/memorydb/list-tags.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 MemoryDB resource by using the [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/tag-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 `memorydb` and `us-east-1` respectively to the cluster `my-cluster` in region us-east-1.

For Linux, macOS, or Unix:

```
aws memorydb tag-resource \
 --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster \
 --tags Key=Service,Value=memorydb \
        Key=Region,Value=us-east-1
```

For Windows:

```
aws memorydb tag-resource ^
 --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster ^
 --tags Key=Service,Value=memorydb ^
        Key=Region,Value=us-east-1
```

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

```
{
   "TagList": [
      {
         "Value": "memorydb",
         "Key": "Service"
      },
      {
         "Value": "us-east-1",
         "Key": "Region"
      }
   ]
}
```

For more information, see the AWS CLI for MemoryDB [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/tag-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-cluster](https://docs.aws.amazon.com/cli/latest/reference/memorydb/create-cluster.html).

## Modifying tags using the AWS CLI
<a name="tagging.managing.cli.modify"></a>

You can use the AWS CLI to modify the tags on a MemoryDB cluster.

To modify tags:
+ Use [tag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/tag-resource.html) to either add a new tag and value or to change the value associated with an existing tag.
+ Use [untag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/untag-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 from a MemoryDB cluster by using the [untag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/untag-resource.html) operation.

The following code uses the AWS CLI to remove the tags with the keys `Service` and `Region` from the cluster `my-cluster` in the us-east-1 region.

For Linux, macOS, or Unix:

```
aws memorydb untag-resource \
 --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster \
 --tag-keys Region Service
```

For Windows:

```
aws memorydb untag-resource ^
 --resource-arn arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster ^
 --tag-keys Region 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 MemoryDB [untag-resource](https://docs.aws.amazon.com/cli/latest/reference/memorydb/untag-resource.html).

# Managing your cost allocation tags using the MemoryDB API
<a name="tagging.managing.api"></a>

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

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

Sample arn: `arn:aws:memorydb:us-east-1:1234567890:cluster/my-cluster`

**Topics**
+ [

## Listing tags using the MemoryDB API
](#tagging.managing.api.List)
+ [

## Adding tags using the MemoryDB API
](#tagging.managing.api.Add)
+ [

## Modifying tags using the MemoryDB API
](#tagging.managing.api.modify)
+ [

## Removing tags using the MemoryDB API
](#tagging.managing.api.Remove)

## Listing tags using the MemoryDB API
<a name="tagging.managing.api.List"></a>

You can use the MemoryDB API to list tags on an existing resource by using the [ListTags](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_ListTags.html) operation.

The following code uses the MemoryDB API to list the tags on the resource `my-cluster` in the us-east-1 region.

```
https://memory-db.us-east-1.amazonaws.com/
   ?Action=ListTags
   &ResourceArn=arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Version=2021-01-01
   &Timestamp=20210802T192317Z
   &X-Amz-Credential=<credential>
```

## Adding tags using the MemoryDB API
<a name="tagging.managing.api.Add"></a>

You can use the MemoryDB API to add tags to an existing MemoryDB cluster by using the [TagResource](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_TagResource.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 MemoryDB API to add the keys `Service` and `Region` with the values `memorydb` and `us-east-1` respectively to the resource `my-cluster` in the us-east-1 region. 

```
https://memory-db.us-east-1.amazonaws.com/
   ?Action=TagResource
   &ResourceArn=arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &Tags.member.1.Key=Service 
   &Tags.member.1.Value=memorydb
   &Tags.member.2.Key=Region
   &Tags.member.2.Value=us-east-1
   &Version=2021-01-01
   &Timestamp=20210802T192317Z
   &X-Amz-Credential=<credential>
```

For more information, see [TagResource](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_TagResource.html).

## Modifying tags using the MemoryDB API
<a name="tagging.managing.api.modify"></a>

You can use the MemoryDB API to modify the tags on a MemoryDB cluster.

To modify the value of a tag:
+ Use [TagResource](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_TagResource.html) operation to either add a new tag and value or to change the value of an existing tag.
+ Use [UntagResource](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_UntagResource.html) to remove tags from the resource.

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

## Removing tags using the MemoryDB API
<a name="tagging.managing.api.Remove"></a>

You can use the MemoryDB API to remove tags from an existing MemoryDB cluster by using the [UntagResource](https://docs.aws.amazon.com/memorydb/latest/APIReference/API_UntagResource.html) operation.

The following code uses the MemoryDB API to remove the tags with the keys `Service` and `Region` from the cluster `my-cluster` in region us-east-1.

```
https://memory-db.us-east-1.amazonaws.com/
   ?Action=UntagResource
   &ResourceArn=arn:aws:memorydb:us-east-1:0123456789:cluster/my-cluster
   &SignatureVersion=4
   &SignatureMethod=HmacSHA256
   &TagKeys.member.1=Service
   &TagKeys.member.2=Region
   &Version=2021-01-01
   &Timestamp=20210802T192317Z
   &X-Amz-Credential=<credential>
```