On this page
Why the connection fails from serverless
An RDS instance lives inside a VPC and always has a private IP address. A client outside that VPC can reach it only when two things are true. The instance has a public IP, which the Public access setting controls. The instance's security group has an inbound rule that matches the client's source address and the database port. AWS's troubleshooting guide puts it plainly. By default, DB instances do not allow access.
Serverless platforms break the second condition. Functions on Vercel, Netlify, Cloudflare, and most PaaS hosts send outbound traffic from shared pools that change between deploys, regions, and cold starts. Vercel's Static IPs docs say that without the add-on, deployments use dynamic IP addresses and Vercel publishes no fixed range to allowlist. The post on why serverless egress IPs change covers each platform's behaviour.
Security groups only have allow rules. A packet that matches none is dropped, so the driver waits and reports a connect timeout, not a refusal. A missing rule looks like a network outage.
The quick fix people find is Public access set to Yes plus an inbound rule for port 5432 from 0.0.0.0/0. It works, and it makes the database password the only control between your data and every scanner on the internet. Allowlisting a whole cloud's published ranges is the same problem in a smaller size, as the post on cloud IP ranges explains.
What public access actually changes
Public access does not open the database by itself. AWS's VPC guide for RDS says that when an instance is publicly accessible, its DNS endpoint resolves to the private IP from inside the VPC and to the public IP from outside it. Access is still controlled by the security group. If no inbound rule permits a source, that source gets nothing.
- Every subnet in the instance's DB subnet group must be public, with a route to an internet gateway. A subnet that later turns private can affect the instance's availability.
- The VPC needs the DNS hostnames and DNS resolution attributes turned on.
- RDS manages the public address. It shows up under Elastic IPs with a
service_managedattribute ofrds, and you cannot release it. - The address is billed like any other public IPv4 address, at $0.005 per hour on the VPC pricing page. That is about $3.65 for a 730-hour month. The post on the AWS public IPv4 charge covers where it appears on the bill.
| Setup | Who can open a TCP connection | Fits serverless |
|---|---|---|
| Private only | Resources in the VPC, peered networks, or a VPN | Only Lambda or containers inside that VPC |
Public access, port open to 0.0.0.0/0 | Any host on the internet | Yes, but the password is the only control |
| Public access, two /32 rules | Only the two listed source addresses | Yes, once the app has fixed egress IPs |
Check where an instance stands before you change anything. The query below prints the public access flag, the endpoint, and the security groups attached to it.
DB=app-db
aws rds describe-db-instances --db-instance-identifier "$DB" \
--query 'DBInstances[0].{public:PubliclyAccessible,host:Endpoint.Address,port:Endpoint.Port,sgs:VpcSecurityGroups[].VpcSecurityGroupId}'
# Turn on public access only after the security group is narrow
aws rds modify-db-instance --db-instance-identifier "$DB" \
--publicly-accessible --apply-immediatelyWhy RDS Proxy does not help from outside AWS
RDS Proxy is the usual advice for serverless and databases, because it pools connections and absorbs bursts of new ones. It does not solve reachability. The RDS Proxy limitations say the proxy must be in the same VPC as the database and cannot be publicly accessible, although the database can be. A function on Vercel or Netlify has no route to it.
RDS Proxy fits when your code runs in your own AWS account. A Lambda function attached to the VPC can reach the proxy privately, and the database security group can reference the proxy's security group instead of any IP address. If you can move the database calls into that shape, you do not need an IP allowlist at all.
From outside AWS you still carry the problem RDS Proxy exists to fix. Each warm function instance holds its own connection, and a spike opens many at once. Keep each instance's pool at one or two connections and watch max_connections. The post on database connections through SOCKS5 covers pools, keepalives, and idle timeouts.
Fixed egress options by platform
The allowlist needs a source address that does not move. Some platforms offer one only on enterprise contracts.
| Platform | Native option | What to know |
|---|---|---|
| Vercel | Static IPs on Pro and Enterprise; Secure Compute on Enterprise; AWS PrivateLink | Static IPs cost $100 per month per project plus Private Data Transfer, with two IPs per region shared by a small group of customers. Builds use dynamic IPs unless you turn on Use for builds. |
| Netlify | Private Connectivity | An add-on to Enterprise plans that needs High-Performance Edge or Build. Functions get static IPs only in the cmh, fra, and lhr regions, and Edge Functions are not covered. |
| Cloudflare Workers | Hyperdrive, or Cloudflare Tunnel into the VPC | Hyperdrive connects from Cloudflare's published IP ranges, which every other Cloudflare customer shares. Raw connect() sockets leave from a prefix outside that published list. |
| Railway | Static outbound IPs on Pro | IPv4 only. Railway does not guarantee the addresses are dedicated, and moving the service to another region changes them. |
| Any platform | A SOCKS5 proxy with fixed exit IPs | Works wherever the driver can open its socket through a proxy. Covered below. |
Details come from Vercel, Netlify, Hyperdrive, Workers sockets, and Railway. A shared static IP is far narrower than 0.0.0.0/0, but other customers exit from it too, so keep strong database credentials.
PrivateLink keeps RDS private, with work on your side
Vercel's PrivateLink connects functions to an AWS endpoint service over the AWS network, and the database never needs a public IP. You have to publish that endpoint service. Vercel supports interface endpoints for services behind a Network Load Balancer, so you put an NLB in front of the database and accept Vercel's IAM role as a principal. The RDS docs note that the instance's underlying IP changes during failover, so plan how the NLB's targets stay current before you rely on it.
Aurora's Data API skips the network question
If the database is Aurora PostgreSQL or Aurora MySQL, the RDS Data API runs SQL over an AWS HTTPS endpoint. Calls are authorized with IAM, database credentials stay in Secrets Manager, and no client needs a route into the VPC. On Vercel, OIDC federation can give functions short-lived AWS credentials for those calls.
The limits are real. Queries run only on the writer, T instance classes are not supported, and a response over 1 MiB is terminated. It is also not a Postgres driver, so code written against pg or an ORM's usual driver needs changes. Plain RDS has no Data API.
Write the security group rule
Put external clients in their own security group. You see at a glance which addresses come from outside, and you can delete the group if you move to PrivateLink later. Security group rules need a /32 prefix for a single IPv4 address, and each rule takes an optional description of up to 255 characters for naming its owner.
DB=app-db
VPC=$(aws rds describe-db-instances --db-instance-identifier "$DB" \
--query 'DBInstances[0].DBSubnetGroup.VpcId' --output text)
# A group only for clients outside the VPC
SG=$(aws ec2 create-security-group --group-name app-db-external \
--description "Fixed egress IPs allowed to reach app-db" \
--vpc-id "$VPC" --query GroupId --output text)
# One /32 per egress IP, on the database port only
aws ec2 authorize-security-group-ingress --group-id "$SG" --ip-permissions \
'IpProtocol=tcp,FromPort=5432,ToPort=5432,IpRanges=[{CidrIp=203.0.113.10/32,Description=prod-egress-a},{CidrIp=203.0.113.11/32,Description=prod-egress-b}]'
# The list replaces what is attached, so include the groups already there
aws rds modify-db-instance --db-instance-identifier "$DB" \
--vpc-security-group-ids sg-0aaaaaaaaaaaaaaaa "$SG" --apply-immediatelyThen look for open rules on every group attached to the instance. Rules from all attached groups add up, so one open rule on an old group undoes the narrow one.
OLD_SG=sg-0aaaaaaaaaaaaaaaa
# Inbound rules open to the whole internet, on IPv4 or IPv6
aws ec2 describe-security-group-rules \
--filters Name=group-id,Values="$OLD_SG" \
--query 'SecurityGroupRules[?!IsEgress && (CidrIpv4==`0.0.0.0/0` || CidrIpv6==`::/0`)].[SecurityGroupRuleId,FromPort,ToPort]' \
--output text
# Remove one by its rule ID once the new path works
aws ec2 revoke-security-group-ingress --group-id "$OLD_SG" \
--security-group-rule-ids sgr-0bbbbbbbbbbbbbbbb- The default quotas are 60 inbound rules per security group and 5 groups per network interface. A pair of egress IPs barely touches either.
- Allow every environment that connects. Previews, cron jobs, and build-time migrations often leave from a different address than production. CI runners are covered in GitHub Actions deploys to allowlisted servers.
- If the instance runs in dual-stack mode, IPv6 needs its own rules. Allow only the address family your egress path actually uses. The post on IPv6 egress and IPv4-only allowlists covers the mismatch cases.
- Ask for two egress IPs on separate hosts, not one. A single address is a single point of failure, as static IP pairs and failover explains.
Keep TLS on and verify the hostname
A public endpoint makes TLS more important, not less. The RDS for PostgreSQL SSL page says rds.force_ssl defaults to 1 on version 15 and later, and to 0 on 14 and older. On an older instance, set it to 1 in a custom parameter group. A client that then tries without TLS gets no pg_hba.conf entry for host "w.x.y.z", user "testuser", database "testDB", SSL off, which is a useful error to recognise.
Forcing TLS is half the job. libpq and JDBC default to sslmode=prefer, which encrypts but never checks who answered. Use verify-full with the RDS trust store. The certificate page publishes a global bundle for all commercial regions, and the default CA is rds-ca-rsa2048-g1. Register only the root certificates, not intermediates, or automatic server certificate rotation can break connections. In Asia Pacific (Mumbai), the rds-ca-rsa4096-g1 and rds-ca-ecc384-g1 CAs are not available, so instances in ap-south-1 stay on the RSA 2048 CA.
curl -sSo global-bundle.pem \
https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
psql "host=app-db.abc123xyz.ap-south-1.rds.amazonaws.com port=5432 \
dbname=app user=app sslmode=verify-full sslrootcert=global-bundle.pem"The server certificate names the instance endpoint, so verify-full passes only when the client checks that exact name. A friendly CNAME in your own domain fails the check. So does a local tunnel on 127.0.0.1, unless the driver is told the real server name separately.
IAM database authentication adds a second layer. The app signs a token that lives 15 minutes and uses it as the password, so a copied connection string stops working quickly. AWS says it needs 300 to 1000 MiB of extra instance memory.
Route the driver through a fixed IP
Without a platform add-on, the portable route is a SOCKS5 proxy with static exit IPs. SOCKS5 carries raw TCP, so the Postgres protocol and its TLS handshake pass through unchanged. The proxy forwards encrypted bytes and never sees queries or the database password. The catch is that the driver must let you supply its socket.
- postgres.js takes a
socketfunction that can be async and returns a duplex stream. Combine it with thesockspackage. - Go's pgx takes a custom
DialFunc. pgx resolves the hostname locally before dialing, so the snippet replacesLookupFuncto hand the proxy the RDS name. That keeps DNS on the proxy side, as socks5 vs socks5h explains, and lets hostname rules on the proxy match. - node-postgres, psycopg, and other libpq clients have no built-in proxy option. Run a local port forward on a host with a long-lived process, such as a Railway or Render service, and point the driver at it.
- Cloudflare Workers open sockets with
connect()and cannot use an ordinary proxy client. The post on edge runtimes and outbound proxies covers what works there.
// npm install postgres socks
import { once } from "node:events";
import { readFileSync } from "node:fs";
import tls from "node:tls";
import postgres from "postgres";
import { SocksClient } from "socks";
// socks5h://user:pass@proxy.example.com:1080
// or socks5s://user:pass@proxy.example.com:1443 for SOCKS5 inside TLS
const proxy = new URL(process.env.SOCKS_PROXY_URL);
const host = process.env.PGHOST; // app-db.abc123xyz.ap-south-1.rds.amazonaws.com
async function openThroughProxy(dbHost, dbPort) {
let existing;
if (proxy.protocol === "socks5s:") {
// Encrypt the hop to the proxy so its credentials are not sent in clear.
existing = tls.connect({
host: proxy.hostname,
port: Number(proxy.port),
servername: proxy.hostname,
});
await once(existing, "secureConnect");
}
const { socket } = await SocksClient.createConnection({
proxy: {
host: proxy.hostname,
port: Number(proxy.port),
type: 5,
userId: decodeURIComponent(proxy.username),
password: decodeURIComponent(proxy.password),
},
command: "connect",
// A hostname, not an IP, so the proxy resolves it.
destination: { host: dbHost, port: Number(dbPort) },
existing_socket: existing,
timeout: 10_000,
});
return socket;
}
// Create once per function instance, outside the handler.
export const sql = postgres({
host,
port: 5432,
database: "app",
username: "app",
password: process.env.PGPASSWORD,
// Postgres TLS runs inside the tunnel and is checked against the RDS name.
// Ship global-bundle.pem with the function.
ssl: { ca: readFileSync("global-bundle.pem"), servername: host },
socket: ({ host: [h], port: [p] }) => openThroughProxy(h, p),
max: 1,
idle_timeout: 60,
});package db
import (
"context"
"net/url"
"os"
"github.com/jackc/pgx/v5/pgxpool"
"golang.org/x/net/proxy"
)
// Connect opens a pool whose connections leave through a SOCKS5 proxy.
func Connect(ctx context.Context) (*pgxpool.Pool, error) {
u, err := url.Parse(os.Getenv("SOCKS_PROXY_URL"))
if err != nil {
return nil, err
}
pw, _ := u.User.Password()
d, err := proxy.SOCKS5("tcp", u.Host,
&proxy.Auth{User: u.User.Username(), Password: pw}, proxy.Direct)
if err != nil {
return nil, err
}
dialer := d.(proxy.ContextDialer)
// postgres://app:PASSWORD@app-db.abc123xyz.ap-south-1.rds.amazonaws.com:5432/app
// ?sslmode=verify-full&sslrootcert=global-bundle.pem
cfg, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
if err != nil {
return nil, err
}
// Skip the local DNS lookup, so the proxy receives the RDS name.
cfg.ConnConfig.LookupFunc = func(_ context.Context, host string) ([]string, error) {
return []string{host}, nil
}
cfg.ConnConfig.DialFunc = dialer.DialContext
cfg.MaxConns = 2
return pgxpool.NewWithConfig(ctx, cfg)
}Both snippets keep verify-full semantics. postgres.js sends its TLS request through the proxied socket and checks the certificate against servername. pgx sets the TLS server name from the host in DATABASE_URL, even though the dialer only sees a proxy. Plain SOCKS5 sends the proxy username and password unencrypted, which is why the Node snippet supports TLS to the proxy. The post on TLS to the proxy covers that hop in more detail.
Roll it out without dropping traffic
- 1Add the narrow rules firstCreate the external security group with one /32 per egress IP and attach it. Leave any open rule in place for now.
- 2Ship the connection change everywhereDeploy the proxy or platform setting to production, previews, scheduled jobs, and build steps. On Vercel, builds only use Static IPs when Use for builds is on.
- 3Check what the database seesRun the query below from a fresh connection in each environment.
client_addrmust be one of your egress IPs andsslmust bet. - 4Remove the open ruleRevoke the
0.0.0.0/0rule by its rule ID. AWS's connection tracking docs say tracked connections survive a rule change until they time out, but a flow allowed by a0.0.0.0/0rule, when the outbound rules are open too, is untracked and drops at once. Expect a missed path to fail quickly. - 5Watch a full dayWatch connection errors through a whole daily cycle, so nightly jobs fail while you are looking.
SELECT a.client_addr, a.application_name, s.ssl, s.version
FROM pg_stat_activity a
JOIN pg_stat_ssl s USING (pid)
WHERE a.usename = current_user;Doing this with Fixedmark
Fixedmark gives an app a pair of static outbound IPs and a SOCKS5 URL, which is the proxy path above. Add both IPs as /32 rules and pass the URL to the driver. Fixedmark is in early access, so the plans and prices below are planned launch values. The Postgres and MySQL use case and the databases guide have the full setup.
- Pick the region next to the database. Mumbai pairs with RDS in
ap-south-1, Singapore withap-southeast-1, and Ashburn withus-east-1. The regions page lists them. - Set
SOCKS_PROXY_URLin the snippets to theFIXEDMARK_SOCKS_URLvalue from the dashboard. Port 1080 is plain SOCKS5, so the token crosses that hop in clear text, while Postgres TLS still protects your data. Port 1443 serves SOCKS5 inside TLS. To use it from the Node snippet, change the URL's scheme tosocks5s://and its port to 1443, and the snippet takes its TLS branch. The Go snippet speaks plain SOCKS5, so keep it on port 1080. The concepts page explains the ports. - For node-postgres, psycopg, or
psqlon a long-running service, run fm tunnel, for examplefm tunnel 5432:app-db.abc123xyz.ap-south-1.rds.amazonaws.com:5432. Keep the RDS name inhostand put127.0.0.1inhostaddrsoverify-fullstill checks the right name. - Production needs a dedicated pair, which starts on Pro at $29 a month. The $9 Starter plan and the trial use a shared pair that other Fixedmark customers also exit from.
- On Business and larger plans, a destination allowlist can limit the token to your RDS endpoint on port 5432, so a leaked token reaches nothing else. The connection logs show the egress IP and destination of each connection while you roll out.
If your database code already runs in your own AWS account, keep it there. A Lambda function in the VPC with RDS Proxy and security group references needs no public IP and no proxy.
Sources
Checked November 2026. Confirm current details on the vendor's site before you decide. Prices and limits change.
- Amazon RDS: working with a DB instance in a VPC
- Amazon RDS: RDS Proxy quotas and limitations
- Amazon RDS: can't connect to a DB instance
- Amazon RDS: using SSL with a PostgreSQL DB instance
- Amazon RDS: SSL/TLS certificates and bundles
- Amazon RDS: IAM database authentication
- Amazon Aurora: using the RDS Data API
- Amazon Aurora: Data API limitations
- Amazon VPC: security group rules
- Amazon VPC: quotas
- Amazon EC2: security group connection tracking
- AWS: Amazon VPC pricing (public IPv4)
- Vercel: Static IPs
- Vercel: AWS PrivateLink
- Netlify: Private Connectivity
- Cloudflare Hyperdrive: firewall and networking configuration
- Cloudflare Workers: TCP sockets
- Railway: static outbound IPs
- postgres.js: README (custom socket)
- pgx: pgconn source (LookupFunc and dialing)

