Cloud & Hosting (AWS)

AWS RDS Setup & Deployment Guide

Managed MySQL and PostgreSQL – create a private database, connect from EC2 and your laptop, use TLS and Secrets Manager, and set up backups and Multi-AZ.

Updated Official documentation ↗

1. Introduction & use cases

Amazon RDS (Relational Database Service) runs databases such as PostgreSQL, MySQL, MariaDB, SQL Server and Oracle for you. AWS handles installation, patching, automated backups, point-in-time recovery, monitoring and optional Multi-AZ standby replicas for high availability. Aurora is AWS’s cloud-native MySQL/PostgreSQL-compatible engine.

You still design the schema, write queries and choose the size – but you no longer maintain the database server itself.

Where it is used

  • Production database for web apps and APIs
  • Replacing a self-managed MySQL/PostgreSQL on a VM
  • Read replicas for reporting and scaling reads
  • Databases that need automated backups and failover

2. Prerequisites

You needVersion / notes
AWS accountWith MFA on the root user and a non-root admin identity
AWS CLI v2Installed and configured – see the AWS guide
VPCThe default VPC is fine to start; production uses private subnets
Clientpsql / mysql CLI, DBeaver or pgAdmin
Local DB for developmentPostgreSQL/MySQL in Docker

3. Local setup

  1. 1Develop against a local database

    Use the same engine and major version locally as in RDS.

    BASH
    docker run -d --name pg -p 5432:5432 -e POSTGRES_PASSWORD=dev -e POSTGRES_DB=app postgres:17
    psql "postgres://postgres:dev@localhost:5432/app" -c "select version();"
  2. 2Create the RDS instance

    RDS console → Create database → Standard create → PostgreSQL (or MySQL) → template Dev/Test or Production → instance db.t4g.micro/small → storage gp3 20 GB → Manage master credentials in AWS Secrets Manager → Public access: No → a new security group rds-sg.

  3. 3Allow only your app servers

    Edit rds-sg inbound rules: PostgreSQL 5432 (MySQL 3306) from the app’s security group (e.g. ec2-app-sg), not from 0.0.0.0/0.

    OUTPUT
    Type         Port   Source
    PostgreSQL   5432   sg-0abc… (ec2-app-sg)

4. Create & run a project

  1. 1Get the endpoint and password

    Copy the endpoint from the console (Connectivity & security). The master password is in Secrets Manager.

    BASH
    aws rds describe-db-instances --db-instance-identifier app-db --query "DBInstances[0].Endpoint.Address" --output text
    aws secretsmanager get-secret-value --secret-id <secret-arn> --query SecretString --output text
  2. 2Connect from the EC2 instance with TLS

    Download the RDS CA bundle and verify the server certificate.

    BASH
    sudo apt install -y postgresql-client
    curl -o global-bundle.pem https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem
    psql "host=app-db.xxxx.ap-south-1.rds.amazonaws.com port=5432 dbname=postgres user=postgres sslmode=verify-full sslrootcert=global-bundle.pem"
  3. 3Create the app database and user

    Do not let the app use the master user.

    SQL
    CREATE DATABASE app;
    CREATE USER app_user WITH PASSWORD 'strong-password';
    GRANT ALL PRIVILEGES ON DATABASE app TO app_user;
    \c app
    GRANT ALL ON SCHEMA public TO app_user;
  4. 4Connect from your laptop through an SSH tunnel

    The database is private, so tunnel through the EC2 instance, then connect to localhost:5433.

    BASH
    ssh -i ~/.ssh/my-ec2-key.pem -N -L 5433:app-db.xxxx.ap-south-1.rds.amazonaws.com:5432 ubuntu@<EC2_IP>
    psql "postgres://app_user@localhost:5433/app?sslmode=require"

✅ When it works you should see output like Figure 1.

5. Development configuration

Environment variables

Keep the connection string out of code. On AWS, read the secret from Secrets Manager at startup (via the instance/task role) or inject it as an environment variable during deployment.

.env
DATABASE_URL=postgres://app_user:PASSWORD@app-db.xxxx.ap-south-1.rds.amazonaws.com:5432/app?sslmode=verify-full&sslrootcert=/etc/ssl/rds/global-bundle.pem
DB_SECRET_ARN=arn:aws:secretsmanager:ap-south-1:123456789012:secret:rds!db-xxxx

Key dependencies

Package / toolUsed for
RDS enginePostgreSQL or MySQL (match local major version)
Security groupsNetwork access only from app servers
Secrets ManagerMaster/app passwords with rotation
RDS CA bundleTLS verification
pg / mysql2 / psycopg / PDODrivers in your app
Performance Insights / CloudWatchQuery and resource monitoring

Folder structure

project structure
app/
├── migrations/        # schema changes (Prisma, Knex, Alembic, Flyway…)
├── src/db.js          # pool using DATABASE_URL
└── certs/global-bundle.pem

Essential commands

CommandWhat it does
aws rds describe-db-instancesList instances and endpoints
aws rds create-db-snapshot --db-instance-identifier app-db --db-snapshot-identifier app-db-pre-releaseManual snapshot
pg_dump / mysqldumpLogical backups
aws rds reboot-db-instanceReboot (applies some parameter changes)

6. Production deployment

Server & hosting requirements

RequirementRecommendation
NetworkPrivate subnets, no public access, SG from app only
High availabilityMulti-AZ for production
BackupsAutomated backups 7–35 days + snapshots before releases
SecurityEncryption at rest, TLS in transit, Secrets Manager
SizingStart small (t4g), watch CPU/memory/IOPS and scale

Deployment steps

  1. 1Production settings

    Modify the instance: enable Multi-AZ, set backup retention (e.g. 14 days), enable deletion protection, encryption (on by default for new instances), Performance Insights and auto minor version upgrades in a maintenance window.

  2. 2Run migrations from your deploy pipeline

    Apply schema changes as a separate, logged step before switching the app to the new version.

    BASH
    # examples
    npx prisma migrate deploy
    python manage.py migrate
    npx knex migrate:latest
  3. 3Snapshot before risky releases

    A manual snapshot is kept until you delete it.

    BASH
    aws rds create-db-snapshot --db-instance-identifier app-db --db-snapshot-identifier app-db-before-v2
  4. 4Monitor and alert

    CloudWatch alarms on CPUUtilization, FreeStorageSpace, DatabaseConnections and FreeableMemory; enable storage autoscaling.

  5. 5Test a restore

    Restore a snapshot to a new instance (point-in-time recovery) and connect to it – the only way to know backups work.

🗺 The whole path from your code to the live site is drawn in the deployment diagram.

7. Images & screenshots

Illustrations drawn for this guide from the commands above. Product dashboards change often, so for screens such as cloud consoles follow the step text and the official documentation.

terminal$ psql "host=app-db.xxxx.ap-south-1.rds.amazonaws.com ... sslmode=verify-full"psql (16.x, server 17.x)SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)Type "help" for help.postgres=> CREATE DATABASE app;CREATE DATABASE
Figure 1: terminal output of the sample AWS RDS project (section 4).
1Local DB in Docker2RDS in privatesubnet3SG: app → 5432only4TLS + SecretsManager5Backups + Multi-AZ
Figure 2: production deployment flow (section 6).
app/├── migrations/ # schema changes (Prisma, Knex, Alembic, Flyway…)├── src/db.js # pool using DATABASE_URL└── certs/global-bundle.pem
Figure 3: project folder structure (section 5).

8. Common errors & solutions

Connection times out

Security group does not allow your source, the instance is private and you are outside the VPC, or wrong port. Allow the app SG or use an SSH tunnel.

password authentication failed

Wrong user/password, or the password was rotated in Secrets Manager – read the current secret.

SSL connection is required / certificate verify failed

Use sslmode=verify-full with the current RDS CA bundle (global-bundle.pem).

too many connections

Each app process opens a pool. Reduce pool sizes, use RDS Proxy, or choose a larger instance class.

Storage full, database read-only

Enable storage autoscaling and alarm on FreeStorageSpace.

Best practices

  • Never make production databases publicly accessible.
  • Use a dedicated app user, not the master user.
  • Multi-AZ, automated backups and deletion protection in production.
  • Use connection pooling and RDS Proxy for serverless apps.
  • Keep local, staging and production on the same engine major version.