C2W1_lab2 create catolog product after creating DB

Course Source Systems, Data Ingestion, and Pipelines

When i attempt to create th productcatelog i keep getting an error, i double checked my work on the solution manual side to ensure i was not making a mistake but even on that side i am still getting error when i run the first exercise. not sure what to do

Output exceeds the size limit. Open the full output data in a text editor

---------------------------------------------------------------------------
ResourceInUseException Traceback (most recent call last)
Cell In[5], line 1
----> 1 response = create_table_db(table_name=product_catalog_table[‘table_name’], **product_catalog_table[“kwargs”])
2 print(response)

Cell In[4], line 5, in create_table_db(table_name, **kwargs)
2 client = boto3.client(“dynamodb”)
3 ### START CODE HERE ### (~ 1 line of code)
----> 5 response = client.create_table(TableName=table_name, **kwargs)
9 ### END CODE HERE ###
11 waiter = client.get_waiter(“table_exists”)

File ~/miniconda/lib/python3.12/site-packages/botocore/client.py:553, in ClientCreator._create_api_method.._api_call(self, *args, **kwargs)
549 raise TypeError(
550 f"{py_operation_name}() only accepts keyword arguments."
551 )
552 # The “self” in this scope is referring to the BaseClient.
→ 553 return self._make_api_call(operation_name, kwargs)

File ~/miniconda/lib/python3.12/site-packages/botocore/client.py:1009, in BaseClient._make_api_call(self, operation_name, api_params)
1005 error_code = error_info.get(“QueryErrorCode”) or error_info.get(
1006 “Code”
1007 )
1008 error_class = self.exceptions.from_code(error_code)

-> 1009 raise error_class(parsed_response, operation_name)
1010 else:
1011 return parsed_response

ResourceInUseException: An error occurred (ResourceInUseException) when calling the CreateTable operation: Table already exists: de-c2w1-dynamodb-ProductCatalog

I was getting a ResourceInUseException when creating a DynamoDB table because the table already existed from a previous run. Restarting or rebooting the lab did not remove the existing table, so the create_table call failed and blocked the rest of the exercise (including creation of the remaining tables).

I resolved this by adding an if check inside the table-creation function to detect and delete the table if it already exists before creating it again. This ensures the notebook can be re-run safely from top to bottom without errors.

Below is the logic I added. This check runs before calling create_table:

existing_tables = client.list_tables()["TableNames"]
if table_name in existing_tables:
    client.delete_table(TableName=table_name)
    client.get_waiter("table_not_exists").wait(TableName=table_name)

This allowed the table to be recreated successfully each time and unblocked the remaining steps in the lab.