Week 5 - botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "http://localhost:8000/"

Connection error means the connection pool was unable to connect to the DB. If your project is configured to attempt the connection to the db using env variables, it's highly likely they may be the culprit.

Error

urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPConnection object at 0x7f9a22c132e0>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

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 42, in list_message_groups
    response = client.query(**query_params)
    ...
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: 
        Could not connect to the endpoint URL: "http://localhost:8000/"
192.168.143.73 - - [02/May/2023 13:09:37] "GET /api/message_groups HTTP/1.1" 500 -

Solution

The env variable for dynamodb AWS_ENDPOINT_URL was missing.

  • ✅ Change (correct) the required variables

      # Change from 
      export AWS_ENDPOINT_URL="http://localhost:8000"
      gp env AWS_ENDPOINT_URL="http://localhost:8000"
    
      # Change to 
      export AWS_ENDPOINT_URL="http://dynamodb-local:8000"
      gp env AWS_ENDPOINT_URL="http://dynamodb-local:8000"
      AWS_ENDPOINT_URL="http://${container-name}:8000"
    
  • ✅ Check your .env file and remove duplicate variables if any.

      REACT_APP_BACKEND_URL="https://4567-${GITPOD_WORKSPACE_ID}.${GITPOD_WORKSPACE_CLUSTER_HOST}"
      REACT_APP_BACKEND_URL="${BACKEND_URL}"   <------ Remove!!
    
    • REACT_APP_BACKEND_URL has duplicate in line 6

      REACT_APP_BACKEND_URL has duplicate in line 6

    • So likely REACT was confused while identifyingwhich REACT_APP_BACKED_URL to use (although both had the same value). Once the duplicates were removed, the issue was resolved.

0
Subscribe to my newsletter

Read articles from Mariachi in a Jar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Mariachi in a Jar
Mariachi in a Jar

Previously cross-cultural communicator, now a machine-human communicator. Currently working as a software QA. Building solid cloud skill sets to transition into the Cloud world.