sethserver.com Subscribe
PostgreSQL database with robotic arms and elephant logo connecting to cloud databases and code editor interface.

How to Connect Replit to AWS RDS PostgreSQL (Without the 3-Hour Timeout Hell)

By Seth Black • Updated: September 17, 2026

Programming · 3 min read

Like this kind of writing? Get one email a week with notes on startups, AI, and the occasional strong opinion about Python: subscribe to the newsletter.

I've lost more afternoons to "just connect the database" than I care to admit. It always starts optimistic. Then you're three hours deep, staring at a timeout, wondering if PostgreSQL has a personal vendetta against you.

Connecting a Replit app to AWS RDS PostgreSQL is simple in the same way "configure DNS" is simple. The steps are short. The ways to mess it up are everywhere.

The three things that must be true

If any of these are wrong, you're not "kind of connected." You're dead in the water.

  1. You have the right RDS endpoint (host)
  2. Your RDS security group allows inbound traffic (network)
  3. Your connection string is valid (auth + format)

Step 1: Get the RDS connection details (don't guess)

In AWS, open your RDS instance. Copy the endpoint. Don't type it by hand - you'll typo it and waste 20 minutes.

It looks like:

your-db-name.abc123xyz.us-east-1.rds.amazonaws.com

You also need:

Step 2: Make RDS publicly accessible (yes, really)

If you're connecting from Replit, your app is not inside your AWS VPC. So your RDS instance needs:

This feels wrong because it is wrong-ish. But it's how most people start.

If you leave it as "No," you'll get timeouts and you'll start blaming libraries. Don't. It's networking.

Step 3: Security group rules (most timeouts live here)

90% of "it hangs forever" is your security group blocking inbound traffic.

Add an inbound rule to the RDS security group:

Yes, that's the entire internet.

Replit also doesn't give you a stable outbound IP by default. So you can't cleanly whitelist your server unless you're on a plan that supports it (Reserved VM / Dedicated VM). If you can get a static outbound IP, do it. Then change the security group source from 0.0.0.0/0 to that single IP.

Don't leave 0.0.0.0/0 in production. I know you will anyway. But don't.

Also: your database is now credential-protected and exposed. Use a strong password. Don't reuse one from your "test123" era.

Step 4: Put the connection string in Replit Secrets

Never hardcode credentials in your repo. Put them in Replit's Secrets (Tools panel).

Set:

Format:

postgresql://[user]:[password]@[host]:[port]/[database]

If your password has special characters (like @ or :), URL-encode it or you'll get "authentication failed" while you swear the password is correct. Because it is correct. And also broken.

Step 5: Code examples that actually work

Python + psycopg2

import os
import psycopg2

DATABASE_URL = os.environ.get("DATABASE_URL")
conn = psycopg2.connect(DATABASE_URL)

Python + SQLAlchemy

import os
from sqlalchemy import create_engine

engine = create_engine(os.environ.get("DATABASE_URL"))

TypeScript + pg (client)

import { Client } from 'pg';

const client = new Client({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: false }
});

await client.connect();

TypeScript + pg (pool, better for real apps)

import { Pool } from 'pg';

const pool = new Pool({
  connectionString: process.env.DATABASE_URL,
  ssl: { rejectUnauthorized: false }
});

SSL: the other "why is this failing" moment

RDS uses SSL. Some clients will complain about cert validation. The pragmatic fix is:

Less secure, but it gets you moving. Another option is adding:

to the end of your connection string.

Troubleshooting: match the symptom to the cause

One more real-world warning: RDS costs money while you sleep. I've seen startups burn $500/month on RDS instances they forgot about. Set a reminder. Delete what you're not using.

If you're stuck, check the security group first. 90% of the time, that's the problem. Even if you're sure you already fixed it.

-Sethers

Share this post
Newsletter

One email, once a week.

Notes on databases, systems, and the occasional strong opinion about Python. No spam, unsubscribe anytime.

Seth Black
Written by

Seth Black

Engineer and founder based in Texas. Writes about databases, AI, and running things in production. Embeds in small teams as lead engineer.

More from Programming

View all →
Programming

What's the Differences Between Relational, NoSQL, Vectors, and Caches

Apr 14, 2026
Programming

Git and Source Control in AI Land

Apr 14, 2026
Programming

Domains, DNS, and why it feels fragile

Apr 14, 2026