10

I've created a PostgreSQL database on AWS, which I want to use for a Django project.

I've modified settings.py so that it has

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': <db name>,
        'USER': <user>,
        'PASSWORD': <password>,
        'HOST': 'projectdevelopment.foobar.us-east-1.rds.amazonaws.com',
        'PORT': '5432',
    }
}

Which I would have thought seemed pretty straightforward. Except that when I try to make a migration I get this error:

django.db.utils.OperationalError: could not translate host name "projectdevelopment.foobar.us-east-1.rds.amazonaws.com" to address: nodename nor servname provided, or not known

The value projectdevelopment.foobar.us-east-1.rds.amazonaws.com has been copied directly from the value under endpoint in the RDS console.

Am I missing a setting, or misconfigured? Or both?

5
  • 1
    Are you connecting from another AWS resource like EC2 or Lambda, or from outside AWS? Have you configured your RDS instance to be accessible from outside AWS? If I remember correctly, by default you can only access if connected by VPC. If it's a very new instance, it may take an hour or two for it to propogate to your DNS provider. Firstly, make sure you can resolve the hostname to an IP address, for example by doing an nslookup or similar DNS query. For example... nslookup my.rdsinstance.us-east-1.rds.amazonaws.com 8.8.8.8 to query Google's public DNS. Commented Jan 18, 2018 at 6:25
  • Yes, it's publicly accessible. And the instance has existed for almost 24 hours now. Commented Jan 18, 2018 at 15:01
  • Can you connect to the instance using pgadmin tool? pgadmin.org Commented Jan 21, 2018 at 0:54
  • If you've made the instance publicly accessible, are you able to connect with the public IP instead of a hostname? The error indicates the hostname can't be resolved. Commented Jan 21, 2018 at 23:46
  • Hey @Batman, i was wondering, did any answer helped? Commented Jan 25, 2018 at 16:22

3 Answers 3

7
+50

Make sure the server is up and running from Amazon's end.

check this issue, They had same problem.


OR

Try to use 'ENGINE' = 'django.db.backends.postgresql_psycopg2', check this SO answer

Read: How To Use PostgreSQL with your Django Application on Ubuntu 14.04


OR

Try to assign DATABASE_URL for connecting RDS postgres to your django app.

DATABASE_URL=postgis://<user>:<password>@<host>:<port>/<db-name>

Note: follow the same syntax for declaring DATABASE_URL, check these special characters in above url.

  • : between user and password,
  • @ between password and host,
  • : between host and port,
  • / between port and db name

and assign it to DATABASES in settings.py

DATABASES['default'] = DATABASE_URL

In your case DATABASE_URL will be.

postgis://<user>:<password>@projectdevelopment.foobar.us-east-1.rds.amazonaws.com:5432/<db name>

  • 5432 is a default port used by postgres server
Sign up to request clarification or add additional context in comments.

Comments

3

It looks like you are using the wrong engine. In addition to this, If you're not using a managed service like Elastic Beanstalk for your application, please make sure you add the security group of your RDS instance to the application environment, so that the application is able to access the RDS instance.

If you're using Elastic Beanstalk: Click here or here

If you're not using elastic beanstalk, most likely the issue is with VPC. Please refer this discussion, to configure EC2 directly with RDS. The scenario is explained well in the official docs here.

Comments

2

Your host string is wrong.

(venv) duddits@dev:~/movina$ host projectdevelopment.foobar.us-east-1.rds.amazonaws.com
Host projectdevelopment.foobar.us-east-1.rds.amazonaws.com not found: 3(NXDOMAIN)


(venv) duddits@dev:~/movina$ dig  projectdevelopment.foobar.us-east-1.rds.amazonaws.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> projectdevelopment.foobar.us-east-1.rds.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30254
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;projectdevelopment.foobar.us-east-1.rds.amazonaws.com. IN A

;; AUTHORITY SECTION:
us-east-1.rds.amazonaws.com. 55 IN      SOA     ns-1420.awsdns-49.org. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400

;; Query time: 0 msec
;; SERVER: 109.197.120.67#53(109.197.120.67)
;; WHEN: Thu Jan 25 04:43:44 +07 2018
;; MSG SIZE  rcvd: 164

This means that there is no host with name projectdevelopment.foobar.us-east-1.rds.amazonaws.com and you'll not be able to connect to it as there is no way to distinguish it's ip address. So you should find correct hostname.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.