Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Deploy Django Rest Framework and React on AWS

I am very new to deploy Django and AWS. So now I would like to deploy my separate project (drf + react) to AWS.

So How can I deploy the separate project to AWS?

EC2 vs Elastic BeanStalk which one is better for that kind of environment?

I already search for one day but I found nothing useful information and found the similar thing but I don't understand like that=> Deploying Separate React Frontend and Django DRF API

like image 913
Loran Avatar asked Jan 03 '20 03:01

Loran


People also ask

Can you use Django and React together?

We also established that when using React and Django together, React serves as the frontend (client-side framework), that handles the UI and getting & setting data via requests to the Django backend, which is an API built using the Django REST framework (DRF).


1 Answers

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.

like image 188
Arun Kamalanathan Avatar answered Oct 16 '22 15:10

Arun Kamalanathan