Managing your cost allocation tags using the Amazon CLI - Amazon MemoryDB for Redis
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Managing your cost allocation tags using the Amazon CLI

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

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

Listing tags using the Amazon CLI

You can use the Amazon CLI to list tags on an existing MemoryDB resource by using the list-tags operation.

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

For Linux, OS X, 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 Amazon CLI for MemoryDB list-tags.

Adding tags using the Amazon CLI

You can use the Amazon CLI to add tags to an existing MemoryDB resource by using the tag-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 Amazon 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, OS X, 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 Amazon CLI for MemoryDB tag-resource.

You can also use the Amazon CLI to add tags to a cluster when you create a new cluster by using the operation create-cluster.

Modifying tags using the Amazon CLI

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

To modify tags:

  • Use tag-resource to either add a new tag and value or to change the value associated with an existing tag.

  • Use untag-resource 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 Amazon CLI

You can use the Amazon CLI to remove tags from an existing from a MemoryDB cluster by using the untag-resource operation.

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

For Linux, OS X, 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 Amazon CLI for MemoryDB untag-resource.