Tagging operations for Amazon Keyspaces - Amazon Keyspaces (for Apache Cassandra)
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).

Tagging operations for Amazon Keyspaces

You can add, list, edit, or delete tags for keyspaces and tables using the Amazon Keyspaces (for Apache Cassandra) console, the Amazon CLI, or Cassandra Query Language (CQL). You can then activate these user-defined tags so that they appear on the Amazon Billing and Cost Management console for cost allocation tracking. For more information, see Cost allocation reports for Amazon Keyspaces.

For bulk editing, you can also use Tag Editor on the console. For more information, see Working with Tag Editor in the Amazon Resource Groups User Guide.

Adding tags to new or existing keyspaces and tables using the console

You can use the Amazon Keyspaces console to add tags to new keyspaces and tables when you create them. You can also add, edit, or delete tags for existing tables.

To tag keyspaces when creating them (console)
  1. Sign in to the Amazon Web Services Management Console, and open the Amazon Keyspaces console at https://console.amazonaws.cn/keyspaces/home.

  2. In the navigation pane, choose Keyspaces, and then choose Create keyspace.

  3. On the Create keyspace page, provide a name for the keyspace. Enter a key and value for the tag, and then choose Add new tag.

  4. Choose Create keyspace.

To tag tables when creating them (console)
  1. Sign in to the Amazon Web Services Management Console, and open the Amazon Keyspaces console at https://console.amazonaws.cn/keyspaces/home.

  2. In the navigation pane, choose Tables, and then choose Create table.

  3. On the Create table page in the Table details section, select a keyspace and provide a name for the table.

  4. In the Schema section, create the schema for your table.

  5. In the Table settings section, choose Customize settings.

  6. Continue to the Table tags – optional section, and choose Add new tag to create new tags.

  7. Choose Create table.

To tag existing resources (console)
  1. Sign in to the Amazon Web Services Management Console, and open the Amazon Keyspaces console at https://console.amazonaws.cn/keyspaces/home.

  2. In the navigation pane, choose Keyspaces or Tables.

  3. Choose a keyspace or table in the list. Then choose Manage tags to add, edit, or delete your tags.

For information about tag structure, see Tagging restrictions for Amazon Keyspaces.

Adding tags to new or existing keyspaces and tables using the Amazon CLI

The examples in this section demonstrate how to use the Amazon CLI to specify tags when you create keyspaces and tables, how to add or remove tags from existing resources, and how to list tags.

The following example shows how to create a new table with tags. The command creates a table myTable in an already existing keyspace myKeyspace. Note that the command has been broken up into different lines to help with readability.

aws keyspaces create-table --keyspace-name 'myKeyspace' --table-name 'myTable' --schema-definition 'allColumns=[{name=id,type=int},{name=name,type=text},{name=date,type=timestamp}],partitionKeys=[{name=id}]' --tags 'key=key1,value=val1' 'key=key2,value=val2'

The following example shows how to add new tags to an existing table.

aws keyspaces tag-resource --resource-arn 'arn:aws:cassandra:us-east-1:111222333444:/keyspace/myKeyspace/table/myTable' --tags 'key=key3,value=val3' 'key=key4,value=val4'

The next example shows how to list the tags of the specified resource.

aws keyspaces list-tags-for-resource --resource-arn 'arn:aws:cassandra:us-east-1:111222333444:/keyspace/myKeyspace/table/myTable'

The output of the last command looks like this.

{ "tags": [ { "key": "key1", "value": "val1" }, { "key": "key2", "value": "val2" }, { "key": "key3", "value": "val3" }, { "key": "key4", "value": "val4" } ] }

Adding tags to new or existing keyspaces and tables using CQL

The following examples show how to use CQL to specify tags when you create keyspaces and tables, how to tag existing resources, and how to read tags.

The following example creates a new keyspace with tags.

CREATE KEYSPACE mykeyspace WITH TAGS = {'key1':'val1', 'key2':'val2'} ;

The following example creates a new table with tags.

CREATE TABLE mytable(...) WITH TAGS = {'key1':'val1', 'key2':'val2'};

To tag resources in a statement with other commands.

CREATE KEYSPACE mykeyspace WITH REPLICATION = {'class': 'Simple Strategy'} AND TAGS = {'key1':'val1', 'key2':'val2'};

The following example shows how to add or remove tags on existing keyspaces and tables.

ALTER KEYSPACE mykeyspace ADD TAGS {'key1':'val1', 'key2':'val2'};
ALTER TABLE mytable DROP TAGS {'key1':'val1', 'key2':'val2'};

To read the tags attached to a resource, use the following CQL statement.

SELECT * FROM system_schema_mcs.tags WHERE valid_where_clause;

The WHERE clause is required, and must be one of the following formats:

  • keyspace_name = 'mykeyspace' AND resource_type = 'keyspace'

  • keyspace_name = 'mykeyspace' AND resource_name = 'mytable'

  • resource_id = arn

Examples:

The following query shows whether a keyspace has tags.

SELECT * FROM system_schema_mcs.tags WHERE keyspace_name = 'mykeyspace' AND resource_type = 'keyspace';

The output of the query looks like the following.

resource_id | keyspace_name | resource_name | resource_type | tags -----------------------------------------------------------------+---------------+---------------+---------------+------ arn:aws:cassandra:us-east-1:123456789:/keyspace/mykeyspace/ | mykeyspace | mykeyspace | keyspace | {'key1': 'val1', 'key2': 'val2'}

The following query is showing the tags for a table.

SELECT * FROM system_schema_mcs.tags WHERE keyspace_name = 'mykeyspace' AND resource_name = 'mytable';

The output of that query looks like the following.

resource_id | keyspace_name | resource_name | resource_type | tags ----------------------------------------------------------------------------+---------------+---------------+---------------+------ arn:aws:cassandra:us-east-1:123456789:/keyspace/mykeyspace/table/mytable | mykeyspace | mytable | table | {'key1': 'val1', 'key2': 'val2'}