1

I have searched through many resources but I haven't found a well-detailed way to set up a Django app on elastic beanstalk using Gunicorn and Nginx with RDS as a database. There are resources available for using it on ec2 machines directly but not through elastic beanstalk.

  1. What steps do I need to follow to make it happen

Also some of the questions I have,

  1. Do we need Nginx when using Django with beanstalk? as beanstalk comes with its own load balancers
  2. I know Django comes with an admin panel which is not a part of Angular. If I were to serve an Angular app through s3 and CloudFront do we still need Nginx to serve static assets? how big of a role does nginx play here?
  3. How many processes/workers and threads are idle for a micro ec2 machine that comes with aws free tier?

thank you in advance

batbark
  • 15
  • 1
  • 6

2 Answers2

1

Going from the other comments, I am going to just first say, make sure you note that some previous answers will be different as AWS Linux 2 is being pushed and it is completely different from the previous version.

And from that I will share with you this Command 01_migrate failed on Amazon Linux 2 AMI

Which is what I needed to do to resolve most of my django + eb + aws linux 2.

0

The official instructions on setting up basic django on EB are:

The instructions are valid as I used them myself. Thus I can verity they work.

You question is too generic to provide detailed answer for everything. But in short, nginx is bundled with EB, so you don't have to do anything. You can customize it to your needs, but no installation is required. Nginx is still used, even if you have load balancer in EB.

Nginx is essential component in EB. It would be difficult to work in EB without it. If you don't want it, maybe easier to setup your own EC2 instance with exactly what you require.

t2.micro has only 1 CPU. AWS does not limit on how many threads or processes you can run. Its dependent on your app and if 1 CPU and 1GB of memory is sufficient for that.

There are two ways of using RDS with on EB. First, is by bundling RDS with EB, second, the recommended, is to use external RDS with EB.

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • thanks for replying. I too use the same instructions usually but there is no mention of setting up gunicorn with it. I will be using gunicorn for the first time so is there any setup file that i have to use with it? In some other tutorials I referred, they use setup in the root of the ec2 directly. but that method is not suitable for beanstalk. What is the work around? – batbark Jul 31 '20 at 07:16
  • @batbark Hi. There is not much settings available for that by default. They are listed [here](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html#command-options-python) and set using `.ebextantions`. For more complex changes you would have to create your own scripts that modify config files. – Marcin Jul 31 '20 at 07:19
  • referring to this https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04 .gunicorn setup is more elaborate. is it necessary to follow these given steps in beanstalk? – batbark Jul 31 '20 at 09:01
  • should we use a procfile with this in it? web: gunicorn --bind :8000 --workers 3 --threads 2 project.wsgi:application – batbark Jul 31 '20 at 09:25
  • @batbark EB already does this. You don't have to set it up by yourself. – Marcin Jul 31 '20 at 10:12
  • i am using postgres rds as my database, i am getting this error '[ERROR] Error occurred during build: Command 01_migrate failed', when i try to migrate using this 01_migrate: command: "django-admin.py migrate" leader_only: true – batbark Aug 01 '20 at 14:49
  • @batbark This is a new issue. The best course of action would be to make new question with details of your files, error messages. In short. Have to inspect logs to see why your command fails. – Marcin Aug 01 '20 at 21:57
  • I did solve migration issue. however i have a new issue 'Command collectstatic failed' this is my command command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic --noinput" how do i check '/var/log/cfn-init.log' for more details – batbark Aug 02 '20 at 09:59
  • @batbark I really think you should make new question, with all these new details and error messages. You have to inspect the logs and check why the command failed. – Marcin Aug 02 '20 at 10:05