How to validate the Label Studio connection to a PostgreSQL database when set up on AWS EC2 using Docker Compose?

Answer:

Checking the Database Connection:

  1. Check the Logs: During the Docker Compose service startup, observe the logs for any PostgreSQL database connection errors. Absence of errors and successful creation of projects indicates Label Studio is connecting to PostgreSQL.
  2. Inspect Database Tables: After Label Studio initialization, review the PostgreSQL database for newly generated tables (e.g., project, task, annotation). Presence and update of such tables signify an active connection.

Environment Variable Configuration:

  • POSTGRE_HOST: Set this to your RDS endpoint, omitting any protocol prefixes (http:// or https://).
  • POSTGRE_PASSWORD: Verify that it is correctly assigned your RDS password.

Ensure that your docker-compose.yml file is correctly set up to pass the environment variables to the Label Studio container. Here’s an example snippet for the app service in your docker-compose.yml:
services:
Docker Compose Service Example:

services:
  app:
    image: heartexlabs/label-studio:latest
    environment:
      - LABEL_STUDIO_HOST=0.0.0.0
      - APP_GID=1002
      - APP_UID=1001
      - DJANGO_DB=default
      - POSTGRE_NAME=labelstudio
      - POSTGRE_USER=labelstudioadmin
      - POSTGRE_PASSWORD=<my_rds_password>
      - POSTGRE_PORT=5432
      - POSTGRE_HOST=<my_rds_endpoint>
    ports:
      - "8080:8080"
    volumes:
      - ./mydata:/label-studio/data

Load Balancer Setup:

Ensure it is configured to redirect traffic to the correct port (default 8080) of your EC2 instance where Label Studio is active.

S3 Integration:
When you’re ready to configure S3, follow the documentation to set up the necessary environment variables for S3 access. Make sure the EC2 instance has the correct IAM role with permissions to access the S3 bucket.