WELLlabs / JaltolAPI

MIT License
0 stars 0 forks source link

Setting up database on AWS #4

Open anmolsingh0219 opened 2 months ago

anmolsingh0219 commented 2 months ago

Setting up database on AWS

Steps implemented in Order (30-07-24)

Current State

bprashanth commented 3 weeks ago

@anmolsingh0219 let's try the following 2 experiments to try and scope the bug.

  1. From the ec2 instance running your django app, execute

    $ docker run -it --rm postgres psql -h jaltoldatabase-1.cnyqeok8kne6.ap-south-1.rds.amazonaws.com -U admindatabase -d postgres -p 5432
  2. If that works, try deploying a very basic django app.

Say something that writes a timestamp to the db everytime you visit /, and reads it back to print on the screen.

# myproject/models.py
from django.db import models

class Visit(models.Model):
    timestamp = models.DateTimeField(auto_now_add=True, verbose_name="Timestamp")

    def __str__(self):
        return f"Visit at {self.timestamp}"

# myproject/urls.py
from django.contrib import admin
from django.urls import path
from django.http import HttpResponse 
from .models import Visit

def hello_world(request):
    Visit.objects.create()
    recent_visit = Visit.objects.latest('timestamp')
    return HttpResponse(f"Hello, world! {recent_visit.timestamp}")

urlpatterns = [
    path('', hello_world),
]

Run that django project in docker the same way, maybe something like

$ docker build -t my_django_app .
$ docker run --name my_django -p 8000:8000 -v $(pwd):/app -d my_django_app
$ docker exec -it my_django python manage.py migrate
...

That is 90% real code, 10% pseudocode. If it's confusing lmk and ill upload my test project.

Make sure your settings.py has the same info in (1)

Depending on which one of those fails, we'll know how to proceed.

bprashanth commented 1 week ago

RDS works.

bprashanth commented 1 week ago

Can you close this issue?