How to Deploy Django Rest Framework and React on AWS How to Deploy Django Rest Framework and React on AWS reactjs reactjs

How to Deploy Django Rest Framework and React on AWS


You asked a difficult question. I think I can make it bit easy for you.

First let's look at the differences in the options.

Serving the front end app

Option1: Django to serve react app

In this option, the Django app will serve your app in a route for e.g /app/. Basically the route /app will load react app's index.html. it's that simple.

In order for this to work, you need to build your react app using npm run build and copy the files to Django's static folder. good so far?One of the benefits option 1 gives, option 2 doesn't is, you can use the same domain for backend and frontend for e.g www.example.com.

Option 2: deploy front end in S3

You still need to build the react app using npm run build, but you will not copy that to Django, in other words, you don't want to Django to serve your front end app, you want s3 to serve the static website. this method requires a separate subdomain or domain to host the react app.

Thats is the only difference between the options. Your frontend app will make api calls to the Django api, thats same for both options.My preferred option is option 2 to reduce complexity.

Deployment

I would pick elasticbeanstalk because it's easy to start with. You can do everything in the elasticbeanstalk console from load balancer to SSL, Healthcheck, Changing EC2 Keypair for EC2 Instance etc. Deployment is very easy. It supports multiple environments, You can use one AWS account for your test and production environments.