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
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).
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.
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
.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With