[Yandex Cloud documentation](../../../../index.md) > [Yandex Managed Service for YDB](../../../index.md) > Amazon DynamoDB-compatible Document API > Tools > [Working with the AWS SDK](index.md) > Deleting a table

# Deleting a table

To delete the `Series` table:

{% list tabs group=programming_language %}

- Java {#java}

  1. Create the `SeriesDeleteTable` project:

      ```bash
      mvn -B archetype:generate \
        -DarchetypeGroupId=org.apache.maven.archetypes \
        -DgroupId=com.mycompany.app \
        -DartifactId=SeriesDeleteTable
      ```

      This command will create the `SeriesDeleteTable` project folder in the current working folder, with a subfolder structure and the `pom.xml` project description file.
  
  1. Go to the project folder:

      ```bash
      cd SeriesDeleteTable
      ```

  1. Edit the project description in the `pom.xml` file, e.g., using `nano`:

      ```bash
      nano pom.xml
      ```

      Example of the `pom.xml` file:

      ```xml
      <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.mycompany.app</groupId>
        <artifactId>SeriesDeleteTable</artifactId>
        <packaging>jar</packaging>
        <version>1.0-SNAPSHOT</version>
        <name>SeriesDeleteTable</name>
        <url>http://maven.apache.org</url>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                                <mainClass>com.mycompany.app.SeriesDeleteTable</mainClass>
                            </manifest>
                            <manifestEntries>
                                <Class-Path>.</Class-Path>
                            </manifestEntries>
                        </archive>
                        <finalName>release/SeriesDeleteTable</finalName>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}/release/lib</outputDirectory>
                                <overWriteReleases>false</overWriteReleases>
                                <overWriteSnapshots>false</overWriteSnapshots>
                                <overWriteIfNewer>true</overWriteIfNewer>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <dependencies>
          <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.1</version>
            <scope>test</scope>
          </dependency>
          <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk-dynamodb</artifactId>
            <version>1.11.1012</version>
          </dependency>
        </dependencies>
        <properties>
          <maven.compiler.source>1.8</maven.compiler.source>
          <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
      </project>
      ```

      Check the current versions of [junit](https://mvnrepository.com/artifact/junit/junit) and [aws-java-sdk-dynamodb](https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-dynamodb).

  1. In the `src/main/java/com/mycompany/app/` folder, create the `SeriesDeleteTable.java` file, e.g., using `nano`:
  
      ```bash
      nano src/main/java/com/mycompany/app/SeriesDeleteTable.java
      ```

      Paste the following code into this file:

      {% note warning %}

      Specify the value you [prepared earlier](index.md#before-you-begin) instead of `<Document_API_endpoint>`.

      {% endnote %}

      ```java
      package com.mycompany.app;

      import com.amazonaws.client.builder.AwsClientBuilder;
      import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
      import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
      import com.amazonaws.services.dynamodbv2.document.DynamoDB;
      import com.amazonaws.services.dynamodbv2.document.Table;

      public class SeriesDeleteTable {

          public static void main(String[] args) throws Exception {

              AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard()
                  .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("<Document_API_endpoint>", "ru-central1"))
                  .build();

              DynamoDB dynamoDB = new DynamoDB(client);

              Table table = dynamoDB.getTable("Series");

              try {
                  System.out.println("Trying to delete the table, wait...");
                  table.delete();
                  table.waitForDelete();
                  System.out.print("Series table deleted.");

              }
              catch (Exception e) {
                  System.err.println("Couldn't delete the table: ");
                  System.err.println(e.getMessage());
              }

          }
      }
      ```

  1. Build the project:

      ```bash
      mvn package
      ```

      This command will create the `SeriesDeleteTable.jar` file in the `target/release/` folder.

  1. Run the application:

      ```bash
      java -jar target/release/SeriesDeleteTable.jar
      ```

      Result:

      ```text
      Attempting to delete table, wait...
      Table Series deleted.
      ```

- Python {#python}

  1. Create the `SeriesDeleteTable.py` file, e.g., using `nano`:
  
      ```bash
      nano SeriesDeleteTable.py
      ```

      Paste the following code into this file:

      {% note warning %}

      Specify the value you [prepared earlier](index.md#before-you-begin) instead of `<Document_API_endpoint>`.

      {% endnote %}

      ```python
      import boto3

      def delete_serie_table():
          ydb_docapi_client = boto3.resource('dynamodb', endpoint_url = "<Document_API_endpoint>")

          table = ydb_docapi_client.Table('Series')
          table.delete()

      if __name__ == '__main__':
          delete_serie_table()
          print("Table Series deleted")
      ```

  1. Run the program:

      ```bash
      python SeriesDeleteTable.py
      ```

      Result:

      ```text
      Table Series deleted.
      ```

- PHP {#php}

  1. Create the `SeriesDeleteTable.php` file, e.g., using `nano`:
  
      ```bash
      nano SeriesDeleteTable.php
      ```

      Paste the following code into this file:

      {% note warning %}

      Specify the value you [prepared earlier](index.md#before-you-begin) instead of `<Document_API_endpoint>`.

      {% endnote %}

      ```php
      <?php

      require 'vendor/autoload.php';

      date_default_timezone_set('UTC');

      use Aws\DynamoDb\Exception\DynamoDbException;

      $sdk = new Aws\Sdk([
          'endpoint' => '<Document_API_endpoint>',
          'region'   => 'ru-central1',
          'version'  => 'latest'
      ]);

      $dynamodb = $sdk->createDynamoDb();

      $params = [
          'TableName' => 'Series'
      ];

      try {
          $result = $dynamodb->deleteTable($params);
          echo "Table deleted.\n";

      } catch (DynamoDbException $e) {
          echo "Couldn't delete table:\n";
          echo $e->getMessage() . "\n";
      }

      ?>
      ```

  1. Run the program:

      ```bash
      php SeriesDeleteTable.php
      ```

      Result:

      ```txt
      Table deleted.
      ```

- Node.js {#node}

  1. Create the `SeriesDeleteTable.js` file, e.g., using `nano`:
  
      ```bash
      nano SeriesDeleteTable.js
      ```

      Paste the following code into this file:

      {% note warning %}

      Specify the value you [prepared earlier](index.md#before-you-begin) instead of `<Document_API_endpoint>`.

      {% endnote %}

      ```javascript
      const AWS = require("@aws-sdk/client-dynamodb");

      // Credentials should be defined via environment variables AWS_SECRET_ACCESS_KEY and AWS_ACCESS_KEY_ID
      const dynamodb = new AWS.DynamoDBClient({
          region: "ru-central1",
          endpoint: "<Document_API_endpoint>",
      });

      dynamodb.send(new AWS.DeleteTableCommand({
          TableName: "Series"
      }))
          .then(data => {
              console.error("Couldn't delete table. JSON error:", JSON.stringify(err, null, 2));
          })
          .catch(err => {
              console.log("Table deleted. Description of JSON table:", JSON.stringify(data, null, 2));
          })
      ```
  
  1. Run the program:

      ```bash
      node SeriesDeleteTable.js
      ```

      Result:

      ```text
      Table deleted. Description of JSON table: {
        "TableDescription": {
          "AttributeDefinitions": [
            {
              "AttributeName": "series_id",
              "AttributeType": "N"
            },
            {
              "AttributeName": "title",
              "AttributeType": "S"
            }
          ],
          "TableName": "Series",
          "KeySchema": [
            {
              "AttributeName": "series_id",
              "KeyType": "HASH"
            },
            {
              "AttributeName": "title",
              "KeyType": "RANGE"
            }
          ],
          "TableStatus": "DELETING",
          "CreationDateTime": "2021-06-14T19:34:32.000Z",
          "TableSizeBytes": 6064,
          "ItemCount": 8
        }
      }
      ```

- Ruby {#ruby}

  1. Create the `SeriesDeleteTable.rb` file, e.g., using `nano`:
  
      ```bash
      nano SeriesDeleteTable.rb
      ```

      Paste the following code into this file:

      {% note warning %}

      Specify the value you [prepared earlier](index.md#before-you-begin) instead of `<Document_API_endpoint>`.

      {% endnote %}

      ```ruby
      require 'aws-sdk-dynamodb'

      def table_deleted?(dynamodb_client, table_name)
        dynamodb_client.delete_table(table_name: table_name)
        true
      rescue StandardError => e
        puts "Error deleting table: #{e.message}"
        false
      end

      def run_me
        region = 'ru-central1'
        table_name = 'Series'

        Aws.config.update(
          endpoint: '<Document_API_endpoint>',
          region: region
        )

        dynamodb_client = Aws::DynamoDB::Client.new

        puts "Deleting a table '#{table_name}'..."

        if table_deleted?(dynamodb_client, table_name)
          puts 'Table deleted.'
        else
          puts 'Couldn't delete table.'
        end
      end

      run_me if $PROGRAM_NAME == __FILE__
      ```

  1. Run the program:

     ```bash
     ruby SeriesDeleteTable.rb
     ```

     Result:

     ```text
     Deleting table 'Series'...
     Table deleted.
     ```

{% endlist %}