academind / django-practical-guide-course-code

This repository holds the source code snapshots for our "Django - The Practical Guide" course (https://acad.link/django)
314 stars 511 forks source link

Problems with psycopg2 and AWS Elastic Beanstalk #2

Open igorkf opened 3 years ago

igorkf commented 3 years ago

In the beginning, everything was fine using only psycopg2-binary in my virtual environment. So I uploaded the code to EB and eveythings goes fine.

When you changed the strategy (start serving static and media files using S3), you needed to install django-storages and change some configurations at settings.py file. Creating static files using this new strategy seems to require psycopg2.extensions which is not available through the binary package (psycopg2-binary). To try to override this problem, I installed psycopg2 in my virtual environment and I could made the static files, but other problem arised: Elastic Beanstalk was not able to install psycopg2.

I came to a solution using this answer: https://stackoverflow.com/a/63204453/11122513

He added a file 01_packages.config inside .ebextensions with this content:

packages:
    yum:
        amazon-linux-extras: []

commands:
    01_postgres_activate:
        command: sudo amazon-linux-extras enable postgresql10
    02_postgres_install:
        command: sudo yum install -y postgresql-devel

Using this solution, EB was able to install psycopg2 and my app worked well again.
You course was really good, but I think the deployment section was a bit tricky and I had to spend some time to be able to do the deploy.

Thanks, Igor