Radar
Radar

Reputation: 25

Django App deployed to EB Could not translate host name

I tried to send an email after an user object gets created. I use celery to perform the task. My application was deployed to AWS Elastic Beanstalk (Linux2 Python3.7). I have one RDS configured for my environment. Whenever I created a new user, my celery worker got the same error as follow:

This is the error I got in celery-worker.log

[2020-08-17 10:51:20,667: INFO/MainProcess] Received task: account.tasks.send_user_email_when_user_created_by_admin[0c202693-43b7-44b7-a9b9-0362bc38afac]
[2020-08-17 10:51:20,675: WARNING/ForkPoolWorker-1] Sending email for new usr
[2020-08-17 10:51:20,693: ERROR/ForkPoolWorker-1] Task account.tasks.send_user_email_when_user_created_by_admin[0c202693-43b7-44b7-a9b9-0362bc38afac] raised unexpected: OperationalError('could not translate host name "aa1rm1r9klym9tk.ce9nktrqundw.us-west-2.rds.amazonaws.com" to address: Name or service not known\n')
Traceback (most recent call last):
  File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
    self.connect()
  File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/var/app/venv/staging-LQM1lest/lib/python3.7/site-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/var/app/venv/staging-LQM1lest/lib64/python3.7/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "aa1rm1r9klym9tk.ce9nktrqundw.us-west-2.rds.amazonaws.com" to address: Name or service not known

This is the code I used for sending an email to user

@receiver(post_save, sender=User)
def create_profile_handler(sender, instance, created, **kwargs):
    if created:
       profile = models.Profile(user=instance)
       profile.save()
       transaction.on_commit(tasks.send_user_email_when_user_created_by_admin.delay(instance.id))

I don't know where this host name came from as I couldn't find such rds under my account. I did the nslookup aa1rm1r9klym9tk.ce9nktrqundw.us-west-2.rds.amazonaws.com 8.8.8.8 and it couldn't find such domain. What caused this issue? How to fix it?

Upvotes: 0

Views: 795

Answers (1)

Ruurtjan Pul
Ruurtjan Pul

Reputation: 1377

The database you're trying to reach doesn't exist under that hostname. There are no DNS records for that domain name: https://www.nslookup.io/dns-records/aa1rm1r9klym9tk.ce9nktrqundw.us-west-2.rds.amazonaws.com/cloudflare/. You probably misconfigured your database settings in Django.

Upvotes: 1

Related Questions