botocore.errorfactory.ResourceInUseException: An error occurred (ResourceInUseException) during CreateTable operation: Cannot create preexisting table

ยท

1 min read

In my case, I was confused with the error message and the actual behaviour of my project -- when I listed tables, there is one table, but when I scanned tables, where were no tables! Why is this ๐Ÿ‘€?

Error

gitpod /workspace/aws-bootcamp-cruddur-2023/backend-flask (submissions) $ ./bin/ddb/schema-load
Traceback (most recent call last):
  File "/workspace/aws-bootcamp-cruddur-2023/backend-flask/./bin/ddb/schema-load", line 20, in <module>
    response = dynamodb.create_table(
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/botocore/client.py", line 530, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/.pyenv_mirror/user/current/lib/python3.11/site-packages/botocore/client.py", line 960, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceInUseException: An error occurred (ResourceInUseException) when calling the CreateTable operation: Cannot create preexisting table

$ ./bin/ddb/scan-tables
{
    "Items": [],         <--------- There is nothing, no items!
    "Count": 0,
    "ScannedCount": 0,
    "ConsumedCapacity": null
}

$ ./bin/ddb/list-tables
----------------------
|     ListTables     |
+--------------------+
|  cruddur-messages  |         <--------- There is one table!!!
+--------------------+

Solution

โœ… 1. Know your code - make sure you understand what each file does.

  • ./backend-flask/bin/ddb/list-tables: lists tables that exist in the database.

  • ./backend-flask/bin/ddb/scan-tables: lists records in a table specified in the command.

      DynamoDB
      โ”œโ”€โ”€ **endpoint-url=http://localhost:8000**
      โ”œโ”€โ”€ **cruddur-messages    <------ list-tables, schema-load 
      โ”‚   โ”œโ”€โ”€ record 1     <---- **scan-tables, seed** one level deeper
      โ”‚   โ”œโ”€โ”€ record 2
      โ”‚   โ”œโ”€โ”€ record 3
      โ”‚   โ”œโ”€โ”€ record ...
      โ”‚   โ”œโ”€โ”€ record n
      โ”‚   โ””โ”€โ”€
    
ย