0

I have a Mongo DB server active at a public port and IP. I want to use that server to access my data from a project I have uploaded to AmazonSageMaker Studio Lab. My problem is that, for some reason, I get a connection error

pymongo.errors.ServerSelectionTimeoutError: [myIP]:[myPort]: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 64662861c3a8cec9e29e9462, topology_type: Unknown, servers: [<ServerDescription ([myIP],[myPort]) server_type: Unknown, rtt: None, error=NetworkTimeout([myIP]:[myPort]: timed out')>]>

The server itself works fine, as I have managed to access that same database from some other third party sources like Google Colab. Is there any reason why my database is not connectable from Amazon SageMaker Studio Lab? And, if so, how can I fix this issue? In case it helps, this is my mongod.conf file:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
#  engine:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,0.0.0.0


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

I also have the authentication set for this database in my docker compose file, but even with the correct connection string, amazon SageMaker is not able to accesss the said database while other third party elements like Google Colab can:

version: "3"
services:  
  mongo-db:
    container_name: mongo-db
    image: mongo:4.4.18
    environment:
      MONGO_INITDB_ROOT_USERNAME: [USERNAME]
      MONGO_INITDB_ROOT_PASSWORD: [PASS]
    volumes:
      - ./mongo_data:/data/db
      - ./mongod.conf:/etc/mongod.conf # mount the custom mongo configuration file
    ports:
      - 27027:27017
    restart: always
  • You run a public accessible MongoDB with disabled security (i.e. without authentication)??? This would be a very bad idea. For a public accessible MongoDB you should also use SSL/TSL encrypted connections. – Wernfried Domscheit May 18 '23 at 18:11
  • I do have authentication for my database, but the code in the Amazon SageMaker project has the complete connection string to access, both with the username and password needed. The thing is that, even having that, the connection can not be stablished, even if from other sources like Colab it is –  May 19 '23 at 05:01
  • Your statement does not match the configuration file you provided. According this authentication is disabled. – Wernfried Domscheit May 19 '23 at 05:47
  • I have the authentication set for this database in my docker compose file, I mean, the ip and port are publicly accessible but the database allocated to that ip and port is not without the correct connection string: `services: mongo-db: container_name: mongo-db image: mongo:4.4.18 environment: MONGO_INITDB_ROOT_USERNAME: [myUser] MONGO_INITDB_ROOT_PASSWORD: [myPass] volumes: - ./mongo_data:/data/db - ./mongod.conf:/etc/mongod.conf # mount the custom mongo configuration file ports: - 27027:27017` –  May 19 '23 at 07:54
  • Still, it does not match. Creating an admin user does not enable authentication, you can connect without any credentials and have full access to the database. Actually it should not work at all, because you mount `/data/db` as data directory but in config file you put `/var/lib/mongodb` – Wernfried Domscheit May 19 '23 at 09:59

0 Answers0