AMAZON SUPPORT
So, I ended up talking with the guys in the Amazon, and after David Woleverโs answer. Just in case, any of you will meet this post again. Using an internal IP server is not enough, but it is a good start. If you are using Ubuntu for your Postgresql instance (preferably Natty Narwhal), make sure that you are editing the pg_hba.conf and postgresql.conf files.
You can usually find these two files at /etc/postgresql/8.4/main/ (pg_hba.conf or postgresql.conf)
Remember, we use Postgresql 8.4 in our stack, it turned out to be the most consistent and reliable version of Postgresql to work on Natty Narwhal during our tests.
For different versions of Postgresql (9.1, 9.0, etc.), the directory in which you can find these two files does not match the above. Make sure you know the appropriate directory for these files.
STEP 1
Go to the Amazon management console and verify that both instances are under the same security group. Postgresql and Django use 5432 and 8000 by default, so make sure these two ports are open!
STEP 2
(do it on the terminal in the postgresql instance)
sudo vim postgresql.conf
Press โiโ on the keyboard to start making changes. Use the DOWN ARROW KEY until you meet
LISTEN_ADDRESSES: "localhost"
Get rid of the hash tag in front, and instead of "localhost" add the private IP address of your postgresql instance (you can find the private ip in the EC2 management console) , and you should also add 127.0.0.1.
Example:
LISTEN_ADDRESSES: 'private ip, 127.0.0.1'
Make sure you separate the private IP address and the local host address with a comma and leave it all under one quote.
After making the changes, press ESC and press ZZ (twice in the caps to save the changes)
STEP 3
sudo vim pg_hba.conf
Use the down arrow key until you come across something similar to this:
Database administrative login by UNIX sockets local all postgres ident # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 md5 local django_db django_login md5 host replication postgres 127.0.0.1/32 md5 host replication postgres ::1/128 md5
Press "i" on the keyboard again and make changes to it exactly as I above it.
You will notice that under IPv6 I have django_db and django_login, change it to the name of your postgresql database and your user name, which you use for your postgresql database, respectively.
After making the changes, press ESC and press ZZ (twice in the caps to save the changes)
STEP 4 (almost done Hi5!)
Restart the postgresql server with this command in the terminal:
sudo / etc / init.d / postgresql restart
Congrats! The server is up and running, however there is the last step.
STEP 5
Launch your instance of Django EC2, go into your settings.py file and find this:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'django_db', 'USER': 'django_login', 'PASSWORD': 'password', 'HOST': '',
In the "HOST": '' section, change it to "HOST": "no matter the private IP address of the Postgresql instance
Save the changes. Open a terminal and find the directory where the manage.py file is located. Once you are in this directory, run the following command: ./manage.py syncdb
They will create all the necessary tables for models created in Django. Congratulations, you have successfully created a link between the database instance and the Django instance.
If you have any questions, I will be more than happy to help! Leave a comment below and I will get back to you as soon as possible! :)