We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Connect App to Database

We've seen that we can use psql from our EC2 instance to connect to the Postgres DB running in RDS. That's no small feat; a bunch of things had to be configured just right for it to work.

The good news is that it will take only one more small step to get the PatientPing app communicating with the database automatically. Instead of using psql manually, we'll set a DATABASE_URL environment variable that the Python app can read when it starts up!

Assignment

The PatientPing app still can't connect to the Postgres database! Fix the problem by adding a .env file with DB connection info on the EC2 instance.

  1. ssh patientping
    cd ~/patientping-web
    

    To keep things simple, make sure the app isn't running at this point.

  2. nano .env
    
  3. DATABASE_URL='postgresql://postgres:[email protected]:5432/patientping'
    
  4. pwd       # /home/ec2-user/patientping-web
    cat .env  # DATABASE_URL='postgresql://postgres:PASSWORD...'
    
  5. uv run patientping.py
    

Keep the PatientPing app running in a separate terminal session while you run and submit the CLI tests.