Skip to content

Setup AWS EC2 instance to connect to RDS Postgres Database

Ian Liu edited this page Sep 27, 2024 · 3 revisions
  1. Go to the AWS console: https://oidc.gov.bc.ca/auth/realms/umafubc9/protocol/saml/clients/amazon-aws, for Forest Client API dev project, click “Login to Console” (if want to setup the instance and connection for test and prod, go to the AWS console for test and prod)
  2. In the console home, search for “EC2” service
  3. On the EC2 page, in the left menu, click on “Instances”, it will show a list of running instances
  4. Create a new EC2 instance by clicking on “Launch instances”
    • name: whatever
    • instance type: could be t2.micro or t2.nano
    • keypair: no need this time
    • network setting: select “Select existing security group”, in the dropdown, select “App_sg”. Could select “Web_sg” as well, but maybe no need
    • and then launch instance
  5. In the instance list, pick the instance by click on its “Instance ID”
Screen Shot 2023-02-02 at 5 02 38 PM 6. In the instance detail page, click on the “Connect” on the top right corner Screen Shot 2023-02-02 at 5 03 14 PM 7. Select “Session Manager” and then “Connect” (note: it could take a few mins before the connect button becomes available) Screen Shot 2023-02-02 at 5 03 30 PM
  1. Once in the Linux shell, install the postgres
    • sudo yum update
    • sudo yum install postgresql Note: If got the error says "Unable to find a match: postgresql", could run a search to see which postgres package is available yum search postgresql, and then pick one from the list, for example sudo yum install postgresql15.x86_64
  2. Connect to the RDS Postgres Database: psql -h dev-fam-cluster-one.cp9oqzf51oiq.ca-central-1.rds.amazonaws.com -p 5432 -U fam_proxy_api famdb
    image
    • hostname could be found by
      • searching “RDS” service
      • select “Database” from the left menu
      • select the cluster with role read or writer instance depending on purpose
      • the endpoint is the hostname
    • database name could be found at the same place, under “Configuration” tab -> “DB name”
    • username “fam_proxy_api” is safer than the admin account
  3. Enter the password, the password could be found by
    • searching “Secret Manager” service
    • select secret name “famdb-api-creds-easy-manatee”
    • in the secret value section, click “Retrieve secret value”
Clone this wiki locally