I followed a tutorial for creating a basic To-Do app (so CRUD) with a React+Axios frontend (ServiceWorker, bootstrap) and Django backend (DjangoREST, corsheaders), and would like to put it on AWS’s free tier for job-finding purposes. I got the app running fine locally using localhost, and even able to get the server running on EC2 and the frontend hosted on S3 using various other tutorials. Now i’m stuck on how to get them to communicate without them being on the same machine. I had hoped I could just change some lines relating to localhost to their IP’s and Ports, but that hasn’t worked. Since this is a fairly simple example program I tried to keep security to a minimum throughout setup to help communications, and have allowed HTTP and HTTPS and anything I could * in my security settings. In settings.py I have:
ALLOWED_HOSTS = ['*']
CORS_ORIGIN_WHITELIST = ['http://frontend-IP:3000']
and in my frontend package.json I have:
"proxy": "http://backend-IP:80",
to tunnel the API to the backend so my axios commands look like:
axios
.get("/api/todos/")
Rather than the whole address. I also am not sure how to make React use something other than localhost:3000 or if i need to change that if its on S3 fine? I tried to test it locally with cross-env, .env, and adding HOST to the package.json but after fiddling it actually damage my ability to npm start the server to the point i had to revert versions.
I don’t have an Elastic Load Balancer on AWS unless i missed that option somewhere setting things up, is that part of it? I’m also a bit lost on if any certs are needed here, as I’ve never deployed an app that had to talk over internet.
I expected hosting on S3 and EC2 would allow me to just change the aforementioned lines to eachother’s IP’s and ports so they could communicate and perform CRUD operations on Django’s db.sqlite3 file.
EDIT: I added an elastic IP to the EC2 through AWS and changed my Axios commands to point to the new IP, but it seems like nothing has changed. I’m wondering if there is just a pointer somewhere that i’m missing.
Gamekeeper is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
9