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).
Use DeleteTable
with an Amazon SDK or CLI
The following code examples show how to use DeleteTable
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code example:
- .NET
-
- Amazon SDK for .NET
-
/// <summary>
/// Delete an Amazon Keyspaces table.
/// </summary>
/// <param name="keyspaceName">The keyspace containing the table.</param>
/// <param name="tableName">The name of the table to delete.</param>
/// <returns>A Boolean value indicating the success of the action.</returns>
public async Task<bool> DeleteTable(string keyspaceName, string tableName)
{
var response = await _amazonKeyspaces.DeleteTableAsync(
new DeleteTableRequest { KeyspaceName = keyspaceName, TableName = tableName });
return response.HttpStatusCode == HttpStatusCode.OK;
}
- Java
-
- SDK for Java 2.x
-
public static void deleteTable(KeyspacesClient keyClient, String keyspaceName, String tableName) {
try {
DeleteTableRequest tableRequest = DeleteTableRequest.builder()
.keyspaceName(keyspaceName)
.tableName(tableName)
.build();
keyClient.deleteTable(tableRequest);
} catch (KeyspacesException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
- Kotlin
-
- SDK for Kotlin
-
suspend fun deleteTable(
keyspaceNameVal: String?,
tableNameVal: String?,
) {
val tableRequest =
DeleteTableRequest {
keyspaceName = keyspaceNameVal
tableName = tableNameVal
}
KeyspacesClient { region = "us-east-1" }.use { keyClient ->
keyClient.deleteTable(tableRequest)
}
}
- Python
-
- SDK for Python (Boto3)
-
class KeyspaceWrapper:
"""Encapsulates Amazon Keyspaces (for Apache Cassandra) keyspace and table actions."""
def __init__(self, keyspaces_client):
"""
:param keyspaces_client: A Boto3 Amazon Keyspaces client.
"""
self.keyspaces_client = keyspaces_client
self.ks_name = None
self.ks_arn = None
self.table_name = None
@classmethod
def from_client(cls):
keyspaces_client = boto3.client("keyspaces")
return cls(keyspaces_client)
def delete_table(self):
"""
Deletes the table from the keyspace.
"""
try:
self.keyspaces_client.delete_table(
keyspaceName=self.ks_name, tableName=self.table_name
)
self.table_name = None
except ClientError as err:
logger.error(
"Couldn't delete table %s. Here's why: %s: %s",
self.table_name,
err.response["Error"]["Code"],
err.response["Error"]["Message"],
)
raise
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.