Tutorial Step 3: Delete a table and a keyspace in Amazon Keyspaces
To avoid being charged for tables and data that you don't need, delete all the tables and keyspaces that you're not using. When you delete a table, the table and its data are deleted and you stop accruing charges for them. However, the keyspace remains. When you delete a keyspace, the keyspace and all its tables are deleted and you stop accruing charges for them.
Delete a table
You can delete a table using the console, CQL, or the Amazon CLI. When you delete a table, the table and all its data are deleted.
The following procedure deletes a table and all its data using the Amazon Web Services Management Console.
To delete a table using the console
-
Sign in to the Amazon Web Services Management Console, and open the Amazon Keyspaces console at https://console.amazonaws.cn/keyspaces/home
. -
In the navigation pane, choose Tables.
-
Choose the box to the left of the name of each table that you want to delete.
-
Choose Delete.
-
On the Delete table screen, enter
Delete
in the box. Then, choose Delete table. -
To verify that the table was deleted, choose Tables in the navigation pane, and confirm that the
book_awards
table is no longer listed.
The following procedure deletes a table and all its data using CQL.
To delete a table using CQL
-
Open Amazon CloudShell and connect to Amazon Keyspaces using the following command. Make sure to update
us-east-1
with your own Region.cqlsh-expansion cassandra.
us-east-1
.amazonaws.com 9142 --ssl -
Delete your table by entering the following statement.
DROP TABLE IF EXISTS catalog.book_awards ;
-
Verify that your table was deleted.
SELECT * FROM system_schema.tables WHERE keyspace_name = 'catalog' ;
The output should look like this. Note that this might take some time, so re-run the statement after a minute if you don't see this result.
keyspace_name | table_name | bloom_filter_fp_chance | caching | cdc | comment | compaction | compression | crc_check_chance | dclocal_read_repair_chance | default_time_to_live | extensions | flags | gc_grace_seconds | id | max_index_interval | memtable_flush_period_in_ms | min_index_interval | read_repair_chance | speculative_retry ---------------+------------+------------------------+---------+-----+---------+------------+-------------+------------------+----------------------------+----------------------+------------+-------+------------------+----+--------------------+-----------------------------+--------------------+--------------------+------------------- (0 rows)
The following procedure deletes a table and all its data using the Amazon CLI.
To delete a table using the Amazon CLI
-
Open CloudShell
-
Delete your table with the following statement.
aws keyspaces delete-table --keyspace-name 'catalog' --table-name 'book_awards'
-
To verify that your table was deleted, you can list all tables in a keyspace.
aws keyspaces list-tables --keyspace-name 'catalog'
You should see the following output. Note that this asynchronous operation can take some time. Re-run the command again after a short while to confirm that the table has been deleted.
{ "tables": [] }
Delete a keyspace
You can delete a keyspace using either the console, CQL, or the Amazon CLI. When you delete a keyspace, the keyspace and all its tables and data are deleted.
The following procedure deletes a keyspace and all its tables and data using the Amazon Web Services Management Console.
To delete a keyspace using the console
-
Sign in to the Amazon Web Services Management Console, and open the Amazon Keyspaces console at https://console.amazonaws.cn/keyspaces/home
. -
In the navigation pane, choose Keyspaces.
-
Choose the box to the left of the name of each keyspace that you want to delete.
-
Choose Delete.
-
On the Delete keyspace screen, enter
Delete
in the box. Then, choose Delete keyspace. -
To verify that the keyspace
catalog
was deleted, choose Keyspaces in the navigation pane and confirm that it is no longer listed. Because you deleted its keyspace, thebook_awards
table under Tables should also not be listed.
The following procedure deletes a keyspace and all its tables and data using CQL.
To delete a keyspace using CQL
Open Amazon CloudShell and connect to Amazon Keyspaces using the following command. Make sure to update
us-east-1
with your own Region.cqlsh-expansion cassandra.
us-east-1
.amazonaws.com 9142 --ssl-
Delete your keyspace by entering the following statement.
DROP KEYSPACE IF EXISTS catalog ;
-
Verify that your keyspace was deleted.
SELECT * from system_schema.keyspaces ;
Your keyspace should not be listed. Note that because this is an asynchronous operation, there can be a delay until the keyspace is deleted. After the keyspace has been deleted, the output of the statement should look like this.
keyspace_name | durable_writes | replication -------------------------+----------------+------------------------------------------------------------------------------------- system_schema | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system_schema_mcs | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} system_multiregion_info | True | {'class': 'org.apache.cassandra.locator.SimpleStrategy', 'replication_factor': '3'} (4 rows)
The following procedure deletes a keyspace and all its tables and data using the Amazon CLI.
To delete a keyspace using the Amazon CLI
Open Amazon CloudShell
-
Delete your keyspace by entering the following statement.
aws keyspaces delete-keyspace --keyspace-name 'catalog'
-
Verify that your keyspace was deleted.
aws keyspaces list-keyspaces
The output of this statement should look similar to this. Note that because this is an asynchronous operation, there can be a delay until the keyspace is deleted.
{ "keyspaces": [ { "keyspaceName": "system_schema", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/system_schema/", "replicationStrategy": "SINGLE_REGION" }, { "keyspaceName": "system_schema_mcs", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/system_schema_mcs/", "replicationStrategy": "SINGLE_REGION" }, { "keyspaceName": "system", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/system/", "replicationStrategy": "SINGLE_REGION" }, { "keyspaceName": "system_multiregion_info", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/system_multiregion_info/", "replicationStrategy": "SINGLE_REGION" } ] }