14

First time using AWS services with Django.

Was wondering how to configure the Django app running in a EC2 instance to a Postgres database in RDS?

the EC2 is running ubuntu 14.04

Any special configuration required?

1
  • 1
    from time to time I get a plus on the answer below, it would be nice for me and the community if you'd accept the answer even though I assume it did not help you personally (due to time difference) Commented Jun 1, 2019 at 5:49

2 Answers 2

24

All you need to do before doing the normal migration documented in the official tutorial is to be sure to have your RDS instance available and accessible to your EC2 instance.

Then, what you need to do is to modify the settings.py file of your app in the DATABASES section in the following way:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': '<name defined upon RDS creation>',
    'USER': '<username defined upon RDS creation>',
    'PASSWORD': '<password defined upon RDS creation>',
    'HOST': '<this can be found in "Endpoint" on your RDS dashboard, exclude the ":" and the port number>',
    'PORT': '5432',
    }
}

Following this, continue to migrate normally and all should work well.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are able to use a deployment service, take a look at at AWS Elastic Beanstalk. It combines EC2, RDS and S3 storage into a Docker and helps keep them together. It's really easy to connect your RDS instance to your EC2 instance(s). I just launched a Django project using that a few weeks ago.

7 Comments

What you mean by deployment service?
Amazon has some services that combine groups of services and ease deployment/maintenance (such as EC2 + RDS + S3). There are a couple, but EB was the most straightforward to me, especially with projects written in Python.
Do you have any good tutorial on this? Particularly for django projects
I found realpython.com/blog/python/… to be the best. It's still a little outdated as EB now supports python 3. Also when you get to the section about handling database migrations use stackoverflow.com/questions/29540131/…
I am a Docker newbie and a EB newbie. I found the realpython.com/blog/python/… not to use Docker. Should I use Docker?
|

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.