1

I'm deploying a django project using zappa to aws-lambda and using mongodb atlas as my database. I'm tring to connect to the database using djongo. I set my django_setting in the zappa_settings.json to my project's django settings. The connection to the database with this settings works just fine in localhost. when deploying, it fails to connect to the server and I suspect that it tries to connect to a default local db (the db sent to mongo_client.py isnt valid or something and it needs to connect to default HOST).

The actual error I get is:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
The above exception was the direct cause of the following exception:  
djongo.sql2mongo.SQLDecodeError: FAILED SQL: SELECT

If anyone has an idea I'd would love to hear.

attaching the settings with some fields unset (but set at my settings) Django settings (database part): DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'db', 'HOST': 'mongodb://<username>:<password>@<> 'USER': 'username', 'PASSWORD': 'password', } }

zappa_settings: { "dev": { "aws_region": "eu-west-1", "django_settings": settings, "profile_name": "default", "project_name": name, "runtime": "python3.6", "s3_bucket": bucket, "timeout_seconds": 900, "manage_roles": false, "role_name": name, "role_arn": arn, "slim_handler": true } }

Eyal
  • 11
  • 2
  • `Connection refused` means the operating system actively refused the connection because there was no process listening on the port. Make sure your IP and port are correct, and any firewalls are configured to allow the connection. – Joe Mar 16 '20 at 23:23
  • Is the Lambda function deployed to a VPC? – Mark B Mar 17 '20 at 13:43
  • No, I am not currently using a VPC, but I whitelisted the MongoDB Atlas to 0.0.0.0/0 – Eyal Mar 17 '20 at 17:05
  • problem solved .. https://stackoverflow.com/questions/60508154/cant-connect-remote-mongodb-server-with-django-djongo – Eyal Mar 17 '20 at 18:52

1 Answers1

0

Try this

    'default': {
    'ENGINE': 'djongo',
    'CLIENT': {
        'host': 'mongodb+srv://url',
        'username': '<username>',
        'password': '<password>',
        'name':'<db_name>'
    }
}