Week 5 - botocore.errorfactory.ResourceNotFoundException: Cannot do operations on a non-existent table
[2023-04-30 20:48:50,640] ERROR in app: Exception on /api/message_groups [GET]
Traceback (most recent call last):
...
File "/backend-flask/app.py", line 209, in data_message_groups
model = MessageGroup.run(cognito_user_id=cognito_user_id)
File "/backend-flask/services/message_group.py", line 23, in run
data = ddb.list_message_groups(dynamodb, current_user_uuid)
File "/backend-flask/lib/ddb.py", line 35, in list_message_groups
response = client.query(**query_params)
...
raise error_class(parsed_response, operation_name)
botocore.errorfactory.ResourceNotFoundException:
An error occurred (ResourceNotFoundException) when calling the Query operation:
Cannot do operations on a non-existent table
Error
Cannot do operations on a non-existent table
Possibiliities
✅ 1. Chekc if DynamoDB container is running.
$ docker ps b699b1fab5eb amazon/dynamodb-local:latest "java -jar DynamoDBL…" \ 23 minutes ago Up 23 minutes \ 0.0.0.0:8000->8000/tcp, :::8000->8000/tcp dynamodb-local
✅ 2. Check env variables used to create DynamoDB client.
Depending on your dev environment, check local machine, gitpod variable store and alike.
class ddb: def client(): endpoint_url = os.getenv("AWS_ENDPOINT_URL") <--------- if endpoint_url: attrs = { 'endpoint_url': endpoint_url } else: attrs = {} dynamodb = boto3.client('dynamodb',**attrs) return dynamodb
✅ 3. Check if the env variables are correctly imported into the docker container.
You can either attach shell to the container, or run this comment on terminal:
docker exec -it <CONTAINER_ID> /bin/bash
# Inside the running flask container: root@a351ce655a9b:/backend-flask# echo $AWS_ENDPOINT_URL http://dynamodb-local:8000
✅ 4. Check if you have correctly seeded some seed data and they are actually on the DB.
Solution
✅ In my case, DynamoDB client was NOT running.