By the end you'll know
- What RDS does for you, what's still your job, and how it compares with running a database on EC2 or using Aurora
- How to build a private database: subnet groups, security groups, encryption and a password kept in Secrets Manager
- Why your own machine can't reach it, and how people reach one anyway
- How point-in-time recovery works, and the gotchas when you use it for real
- The difference between Multi-AZ and read replicas, which the exam asks every time
- What Aurora adds, and when it's worth the cost
Before you start
- You need: the
juniper-ryeprofile from Lesson 4, signed in, and Lessons 9, 11 and 13: security groups, Run Command, and private subnets. The SQL track's Your first database coverspsqlitself. - The script:
db-lab.shfrom the practice folder'slesson-17. Everything it creates is namedjr-lesson17-*, and itsdeletestep removes it. - How the script talks to AWS: only through the AWS CLI. The few lines of Python in it just turn the CLI's JSON into readable tables and never connect to AWS; boto3, AWS's Python library, comes in Lesson 20.
- To see every call the script makes, put
SHOW=1in front of any step, such asSHOW=1 ./db-lab.sh build. The lesson's "By hand" section lists them all too. - Where you run things: your own machine, labeled (Your machine). The database commands run on the app server, labeled (On the server).
- Time: databases are slow to make and delete. The whole lab takes about 70 minutes, most of it waiting.
- Every output below is from a real run on November 11, 2026. A first run failed at the restore step, and the lesson says why.
A database bills every hour it exists, busy or not
An idle db.t4g.micro still costs about $12 a month, and Multi-AZ doubles it. Stopping one only pauses it for seven days: then RDS starts it again by itself, and billing restarts. Delete what you aren't using. The lab's delete skips the final snapshot because the data is made up; for real data, keep one.
The short version
- RDS (Relational Database Service) runs the database server for you: installing, patching, backups, failover and storage. The tables, queries and users are still yours.
- A private database lives in private subnets in two zones, with a security group that lets in only the app's security group.
- Point-in-time recovery restores to any second in the backup window, as a new database with a new address. It doesn't overwrite the old one.
- Multi-AZ keeps a standby in another zone for failover; read replicas are copies for reading. One is for surviving, the other for scaling.
- Aurora is AWS's own database engine, compatible with PostgreSQL and MySQL, with storage spread over three zones and faster failover, at a higher price.
What this lesson costs
| Part | Cost |
|---|---|
| db.t4g.micro, Single-AZ | About $0.016 an hour |
| The same, Multi-AZ | About $0.032 an hour |
| 20 GiB gp3 database storage | $0.115 per GB a month, by the hour: about $0.003 an hour |
| Automated backups | Free up to the database's size |
| The password's secret in Secrets Manager | $0.40 a month, by the hour |
| The app server, with a public IPv4 address | About $0.013 an hour |
| This lesson | About 20 cents, from credits |
Why let AWS run the database
The bakery could install PostgreSQL on an EC2 server, as Lesson 10 installed a web server. Plenty of teams did, for years. The difference is who does the work:
| Job | On EC2 | RDS | Aurora |
|---|---|---|---|
| Install and patch the database software | You | AWS, in a window you choose | AWS |
| Backups, and restoring to a point in time | You build it | Built in | Built in, and continuous |
| A standby in another zone | You build replication | One setting: Multi-AZ | Built into the storage |
| Storage that grows | You, as in Lesson 16 | Storage autoscaling | Automatic, as the data grows |
| SSH to the server | Yes | No: there's no server you can reach | No |
| Tables, queries, indexes, users | You | You | You |
That last row is Lesson 2's shared responsibility model again: AWS runs the database server, and what's in it is yours, including a careless DELETE. RDS offers PostgreSQL, MySQL, MariaDB, Oracle, SQL Server and Db2; Aurora comes in PostgreSQL- and MySQL-compatible versions. Lesson 18's DynamoDB is a different kind of database altogether, without tables of rows and columns.
Is it allowed, and what does it cost?
(Your machine)
cd ~/Apps/aws-practice/lesson-17
chmod +x db-lab.sh
./db-lab.sh fence
== Is this allowed in us-east-2?
PostgreSQL's default version 18.3
db.t4g.micro offered in 3 zones
launch the app server allowed
RDS allowed to read (RDS has no dry run; build will show the rest)
== What it costs, in us-east-2
db.t4g.micro database: about $0.016 an hour, Single-AZ; Multi-AZ doubles it
20 GiB gp3 database storage: $0.115 per GB a month, by the hour: about $0.003 an hour
backups: free up to the size of the database
the password's secret: $0.40 a month, by the hour: a fraction of a cent
the app server: about $0.013 an hour, with its public IPv4 address
this lab: about 10 cents with restore, about 20 with failover, if delete runs the same day
The fence asks RDS which PostgreSQL version is its default, 18.3, and whether the smallest database size is offered here. It is, in all three zones.
A private database
In the console: RDS > Create database > Standard create > PostgreSQL. Under Credentials management, choose Managed in AWS Secrets Manager. Under Connectivity, pick the VPC, Public access: No, and the database's security group.
(Your machine)
./db-lab.sh build
== A VPC: a public subnet for the app server, and two private subnets for the database
== A DB subnet group: the private subnets the database may use, in two zones
== The database: PostgreSQL 18.3, db.t4g.micro, 20 GiB, private, encrypted, password in Secrets Manager
== The app server, in the public subnet, with no inbound rules
== Waiting for the database (usually 5 to 10 minutes)
available after 442 seconds
== The app server may read the database's secret, and nothing else
app server online
== What was built
engine postgres 18.3
class db.t4g.micro
storage 20 GiB gp3, encrypted True
zone us-east-2a, Multi-AZ False
endpoint jr-lesson17-db.cpimqeq6mvey.us-east-2.rds.amazonaws.com, port 5432
publicly accessible False
backups kept 1 day
password in Secrets Manager, status active
The two calls that matter:
aws rds create-db-subnet-group --db-subnet-group-name jr-lesson17-subnets \
--db-subnet-group-description "Juniper & Rye database subnets" --subnet-ids "$DB_SUBNET_A" "$DB_SUBNET_B"
aws rds create-db-instance --db-instance-identifier jr-lesson17-db --engine postgres --engine-version 18.3 \
--db-instance-class db.t4g.micro --allocated-storage 20 --storage-type gp3 --storage-encrypted \
--master-username bakery_admin --manage-master-user-password --db-name bakery \
--db-subnet-group-name jr-lesson17-subnets --vpc-security-group-ids "$DB_SG" \
--no-publicly-accessible --no-multi-az --backup-retention-period 1 --copy-tags-to-snapshot
| Setting | Does |
|---|---|
| DB subnet group | The subnets RDS may put the database in. It needs two zones even for one database, so a standby has somewhere to go later. |
--vpc-security-group-ids | jr-lesson17-db-sg: port 5432 from the app server's security group only, Lesson 9's pattern |
--no-publicly-accessible | No public address. Combined with private subnets, nothing outside the VPC can reach it. |
--storage-encrypted | Only possible when the database is made. An unencrypted one can't be switched later: you'd snapshot it, copy the snapshot encrypted, and restore. |
--manage-master-user-password | RDS makes the password and keeps it in Secrets Manager, and can change it on a schedule. Nobody types it, and it's in no script. |
--backup-retention-period 1 | Keep automated backups for 1 day: enough for the lab. The console's default is 7, and the most is 35. |
Building took 442 seconds, about seven and a half minutes. The endpoint is the database's address, a DNS name that stays the same whatever happens to the server behind it, which matters in the failover section.
Reaching it
(Your machine)
./db-lab.sh connect
== From the app server: who am I talking to, and is it encrypted?
server: PostgreSQL 18.3
its address: 10.17.11.8/32
encrypted connection: true, TLSv1.3
== Create the orders table, and take three orders
id | item | qty
----+-----------+-----
1 | sourdough | 2
2 | rye | 1
3 | croissant | 6
(3 rows)
== And from your own machine?
your machine's DNS: no answer ([Errno 8] nodename nor servname provided, or not known)
a public DNS server, 1.1.1.1: 10.17.11.8
connecting to 10.17.11.8 port 5432: timed out
Every database command the script sends to the app server starts the same way:
(On the server)
export PGPASSWORD=$(aws secretsmanager get-secret-value --region us-east-2 --secret-id "$SECRET_ARN" \
--query SecretString --output text | python3 -c 'import json,sys; print(json.load(sys.stdin)["password"])')
export PGHOST=jr-lesson17-db.cpimqeq6mvey.us-east-2.rds.amazonaws.com PGUSER=bakery_admin PGDATABASE=bakery PGSSLMODE=require
psql -c "select id, item, qty from orders order by id"
The password never left AWS. The app server's role has one extra permission: secretsmanager:GetSecretValue on that one secret, and nothing else, Lesson 3's least privilege. The server fetches the password into a variable, psql reads it from there, and it never appears in the script, the output or your terminal.
The connection used TLS 1.3, encrypted on the wire. PGSSLMODE=require insists on it, and RDS for PostgreSQL refuses unencrypted connections by default.
Your machine can't reach it, twice over
The endpoint is a public DNS name, but it resolves to the database's private address, 10.17.11.8, as 1.1.1.1 showed. Your machine's own DNS gave no answer at all: many home routers and DNS filters drop answers that point at private addresses, as a guard against an attack called DNS rebinding. Even with the address, the connection timed out, because 10.17.11.8 is inside the VPC and nothing outside has a route to it. The Networking track's DNS and Routing, NAT and private networks lessons cover both halves.
To use a desktop tool like pgAdmin against a private database, teams use Lesson 11's Session Manager: the AWS-StartPortForwardingSessionToRemoteHost document forwards a port on your machine, through an EC2 server in the VPC, to the database, with no open ports and no public address.
The accident, and getting the orders back
In the console: RDS > Databases > the database > Actions > Restore to point in time, then choose a time and a name for the new database.
(Your machine)
./db-lab.sh restore
== The orders, and the time on the database's clock
3 orders
2026-11-11T16:03:50Z
== The accident: a DELETE with no WHERE
DELETE 3
0 orders left
== Waiting until RDS can restore to 2026-11-11T16:03:50Z (its latest restorable time trails by about 5 minutes)
latest restorable time: 2026-11-11T16:08:07+00:00
== Restoring to 2026-11-11T16:03:50Z, as a new database: jr-lesson17-restored
available after 574 seconds
it has the password the original had at 2026-11-11T16:03:50Z, so the original's secret still opens it
== The two databases now
jr-lesson17-db: 0 orders
jr-lesson17-restored: 3 orders
== The orders in the restored copy
id | item | qty
----+-----------+-----
1 | sourdough | 2
2 | rye | 1
3 | croissant | 6
(3 rows)
DELETE FROM orders, with no WHERE, deleted every order. It's the most famous mistake in SQL, and the SQL track's Changing data safely is about not making it. When it happens anyway:
aws rds restore-db-instance-to-point-in-time --source-db-instance-identifier jr-lesson17-db \
--target-db-instance-identifier jr-lesson17-restored --restore-time 2026-11-11T16:03:50Z \
--db-instance-class db.t4g.micro --db-subnet-group-name jr-lesson17-subnets \
--vpc-security-group-ids "$DB_SG" --no-publicly-accessible
Automated backups are a daily snapshot plus the database's change log, copied every five minutes, which is why RDS can rebuild the database as it was at any second in the retention window. The "latest restorable time" trails behind: the lab waited until it reached 16:08, past the 16:03:50 it needed.
Three things about the result catch people out:
| It | So |
|---|---|
| Makes a new database, with a new endpoint | The broken one is untouched, still with 0 orders. You either copy the missing rows across, or point the app at the new one. |
| Uses the default security group unless told otherwise | The lab passed --vpc-security-group-ids. Forget it, and the app's connections time out. |
| Has the password from that moment | It isn't linked to a secret of its own. The lab's first run asked RDS for a new managed password during the restore, and RDS refused: it isn't allowed for PostgreSQL restores. The original's secret opened it instead. |
It took 574 seconds, nearly ten minutes, plus five of waiting for the restorable time to catch up. That's the real recovery time for even a tiny database, and the exam's name for it, RTO (recovery time objective), is Lesson 19's subject.
Manual snapshots, with create-db-snapshot, are the other kind of backup: they're kept until you delete them, even after the database is gone, whereas automated backups go with the database unless you ask to keep them.
Multi-AZ: a standby in another zone
In the console: the database > Modify > Availability and durability > Create a standby instance, then Apply immediately. To test it: Actions > Reboot > Reboot with failover.
(Your machine)
./db-lab.sh failover
== Adding a standby in another zone (Multi-AZ). The database stays up while it's built.
right after asking: status, Multi-AZ, zone, standby zone, pending: available False us-east-2a None True
after 497 seconds: available True us-east-2a None None
primary in us-east-2a, standby in None
== Failing over, while the app server asks the database for the time once a second
failover started at 16:29:16 UTC
16:29:06 up
16:29:29 down
16:29:39 up
primary now in us-east-2b, standby in us-east-2a
the endpoint the app uses, unchanged: jr-lesson17-db.cpimqeq6mvey.us-east-2.rds.amazonaws.com
aws rds modify-db-instance --db-instance-identifier jr-lesson17-db --multi-az --apply-immediately
aws rds reboot-db-instance --db-instance-identifier jr-lesson17-db --force-failover
Multi-AZ keeps a second copy of the database in another zone, kept up to date with every write before the write counts as done: synchronous replication. Nobody can query the standby; it waits. If the primary's zone fails, its server fails, or AWS patches it, RDS switches the endpoint's DNS name to the standby, and the app reconnects to the same name.
The output shows each stage. Right after the request, Multi-AZ was still False, with the change pending: True. About eight minutes later it was True, with the database up throughout. The standby's zone showed None until after the first failover: RDS doesn't report it until then, which is how the lab's first run looked as if there were no standby. Then the failover: down at 16:29:29, back at 16:29:39, about ten seconds, and the primary was in us-east-2b. Same endpoint, so the app changed nothing.
AWS says failovers typically take one to two minutes; ten seconds was a quiet database and a lucky run. Plan for the minutes.
Multi-AZ or a read replica?
The exam's favorite RDS question, because the two sound alike:
| Multi-AZ standby | Read replica | |
|---|---|---|
| For | Surviving a failure | Spreading out reads |
| Copying | Synchronous: every write, before it counts | Asynchronous: a little behind |
| Can you query it? | No | Yes, read-only |
| Where | Another zone, same Region | Any zone, or another Region |
| How many | One (or two readable ones, in a Multi-AZ DB cluster) | Up to 15 |
| On failure | Takes over automatically, same endpoint | You promote it by hand; it gets its own endpoint |
The patterns: "survive a zone failure" is Multi-AZ; "reports are slowing the database down" is a read replica; "recover from a Region failure" is a read replica in another Region, promoted.
Aurora, described
Aurora is AWS's own database engine, compatible with PostgreSQL or MySQL, so the same psql and the same SQL work. The difference is underneath: Aurora's storage is a shared layer that keeps six copies of the data across three zones, and the database servers sit on top of it.
| Aurora | Compared with RDS |
|---|---|
| Storage in three zones, six copies, growing by itself | RDS stores data on EBS in one zone, plus the standby's copy |
| Up to 15 replicas that read the same storage | No copying lag to speak of, and any can take over |
| Failover usually under 30 seconds | RDS Multi-AZ: typically one to two minutes |
| Serverless v2 | Scales its size up and down with load, even to zero when idle |
| Global Database | Copies to other Regions within about a second |
| Price | Higher: more per hour for the same size, plus storage and, unless you choose I/O-Optimized, each read and write |
The lab doesn't build Aurora: a small Aurora cluster costs several times this lab's database, and RDS shows the same ideas. Choose Aurora when the database is central and busy: many readers, fast failover, global copies. For a bakery's orders, RDS is plenty.
Take it down
In the console: the database > Actions > Delete. It asks whether to take a final snapshot and whether to keep automated backups; for real data, say yes to the snapshot.
(Your machine)
./db-lab.sh delete
== Deleting database jr-lesson17-restored (its backups and its password's secret go with it)
== Deleting database jr-lesson17-db (its backups and its password's secret go with it)
== Databases deleted
== Deleted the DB subnet group
== Terminated the app server
== Deleted role jr-lesson17-app-role
== Deleted jr-lesson17-vpc and everything in it
== Left over from this lab
databases: 0
DB subnet groups: 0
servers: 0
VPCs: 0
== Database things that bill, anywhere in us-east-2
database instances: 0
Aurora clusters: 0
manual snapshots: 0
kept backups: 0
secrets: 0
aws rds delete-db-instance --db-instance-identifier jr-lesson17-db --skip-final-snapshot --delete-automated-backups
--skip-final-snapshot and --delete-automated-backups mean nothing is kept: right for made-up orders, wrong for real ones. Without them, RDS keeps a final snapshot and the automated backups, which go on billing. The managed password's secret is deleted with its database. The last section counts anything database-related still billing anywhere in the Region.
By hand: every command the script runs
The same lab without the script, in order. It leaves out tags and waiting loops; SHOW=1 ./db-lab.sh build prints the exact calls as they run, with the secret's ARN hidden. (Your machine), with the database commands sent to the app server through Run Command.
export AWS_PROFILE=juniper-rye AWS_REGION=us-east-2
# Network: a public subnet in us-east-2a for the app server, private subnets in us-east-2a and us-east-2b
# for the database, and a database security group allowing 5432 from the app's group only
aws ec2 authorize-security-group-ingress --group-id "$DB_SG" --protocol tcp --port 5432 --source-group "$APP_SG"
# The database
aws rds create-db-subnet-group --db-subnet-group-name jr-lesson17-subnets \
--db-subnet-group-description "Juniper & Rye database subnets" --subnet-ids "$DB_SUBNET_A" "$DB_SUBNET_B"
aws rds create-db-instance --db-instance-identifier jr-lesson17-db --engine postgres --engine-version 18.3 \
--db-instance-class db.t4g.micro --allocated-storage 20 --storage-type gp3 --storage-encrypted \
--master-username bakery_admin --manage-master-user-password --db-name bakery \
--db-subnet-group-name jr-lesson17-subnets --vpc-security-group-ids "$DB_SG" \
--no-publicly-accessible --no-multi-az --backup-retention-period 1 --copy-tags-to-snapshot
aws rds wait db-instance-available --db-instance-identifier jr-lesson17-db
# The app server's role may read this one secret
SECRET_ARN=$(aws rds describe-db-instances --db-instance-identifier jr-lesson17-db \
--query 'DBInstances[0].MasterUserSecret.SecretArn' --output text)
aws iam put-role-policy --role-name jr-lesson17-app-role --policy-name read-db-secret --policy-document \
"{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"secretsmanager:GetSecretValue\",\"Resource\":\"$SECRET_ARN\"}]}"
# Point-in-time recovery, after the accident
aws rds describe-db-instances --db-instance-identifier jr-lesson17-db --query 'DBInstances[0].LatestRestorableTime'
aws rds restore-db-instance-to-point-in-time --source-db-instance-identifier jr-lesson17-db \
--target-db-instance-identifier jr-lesson17-restored --restore-time 2026-11-11T16:03:50Z \
--db-instance-class db.t4g.micro --db-subnet-group-name jr-lesson17-subnets \
--vpc-security-group-ids "$DB_SG" --no-publicly-accessible --no-multi-az
# Multi-AZ, and a failover
aws rds modify-db-instance --db-instance-identifier jr-lesson17-db --multi-az --apply-immediately
aws rds reboot-db-instance --db-instance-identifier jr-lesson17-db --force-failover
# Taking it down
aws rds delete-db-instance --db-instance-identifier jr-lesson17-restored --skip-final-snapshot --delete-automated-backups
aws rds delete-db-instance --db-instance-identifier jr-lesson17-db --skip-final-snapshot --delete-automated-backups
aws rds wait db-instance-deleted --db-instance-identifier jr-lesson17-db
aws rds delete-db-subnet-group --db-subnet-group-name jr-lesson17-subnets
# then the app server, the role and the VPC, as in earlier lessons
In real systems
- Production databases are Multi-AZ, with backups kept 7 to 35 days, plus manual or AWS Backup snapshots copied to another Region (Lesson 19).
- Upgrades use blue/green deployments: RDS builds an upgraded copy, keeps it in step, and switches over in about a minute.
- Apps reach the database through RDS Proxy when there are many short connections, as from Lambda functions (Lesson 21), so the database isn't swamped.
- People and apps can sign in with IAM instead of a password, using short-lived tokens: IAM database authentication.
- Settings like timeouts and logging live in a parameter group, not on the server, because there's no server to log in to.
- It's all Terraform, with the password left to Secrets Manager and never written in the code (Part 5's Terraform lesson).
Spot the problem
Work out what's wrong before you read the explanation.
"We restored the database, and now nothing can connect to it." After a bad data migration, a team restores the orders database to an hour earlier, from the console, as orders-restored. They point the app at its endpoint. Every connection times out. The database shows available, and the password is right. What's wrong? A restored database gets the VPC's default security group unless you choose one, and the default group doesn't allow port 5432 from the app's security group. The fix: modify orders-restored to use the same security group as the original database. Then check: does a connection from the app server, like the lab's psql -c "select 1", succeed?
Keep this
| Remember | Why |
|---|---|
| RDS runs the server; the data is yours | It can't stop a bad DELETE |
| Private subnets in two zones, public access off | Your own machine couldn't reach it at all |
| Encrypt when you create it | It can't be switched on later |
| Passwords in Secrets Manager, read by role | Nobody sees them, nothing stores them |
| Point-in-time restore makes a new database | New endpoint, and set its security group |
| Multi-AZ to survive; read replicas to scale | The exam's favorite RDS question |
| Failover keeps the endpoint | The primary moved zones; the app changed nothing |
| Aurora for central, busy databases | Faster failover and more replicas, at a higher price |
| Stopped databases restart after 7 days | Delete what you don't use |
Where you are now
The bakery's orders live in a private PostgreSQL database your own machine can't reach, opened by a password nobody has seen. You deleted every order and got them back from the second before, and watched the database move to another zone in about ten seconds without the app changing a thing. Next, Lesson 18 is a different kind of database: DynamoDB, with no servers to size at all.
Check yourself
Your machine looked up the endpoint through a public DNS server. Why still no connection?
How did the app server get the database password?
After the point-in-time restore, how many orders did the original database have?
Why did the lab wait before restoring to 16:03:50?
Reports are slowing down the bakery's database. What helps?
After the failover, what did the app need to change?
When is Aurora worth its higher price?
Key terms
- RDS (Relational Database Service): AWS running a database server for you.
- DB instance: one RDS database server.
- DB subnet group: the subnets, in at least two zones, RDS may use.
- Endpoint: the database's DNS name, which stays the same through failovers.
- Secrets Manager: stores secrets like passwords, readable only with permission, and can change them on a schedule.
- Automated backups: daily snapshots plus the change log, kept for the retention period.
- Point-in-time recovery: restoring to any second in the backup window, as a new database.
- Manual snapshot: a backup you take, kept until you delete it.
- Multi-AZ: a synchronous standby in another zone that takes over on failure.
- Failover: switching to the standby.
- Read replica: an asynchronous, readable copy, for spreading out reads.
- Aurora: AWS's PostgreSQL- and MySQL-compatible engine with shared storage across three zones.
- Aurora Serverless v2: Aurora that scales its size with load.
Go deeper
- SQL track: Your first database, Changing data safely and Backups, and restoring them.
- Networking track: DNS and Routing, NAT and private networks.
- AWS: Multi-AZ deployments (opens in a new tab), point-in-time recovery (opens in a new tab), and password management with Secrets Manager (opens in a new tab).
- AWS: read replicas (opens in a new tab), Aurora (opens in a new tab), and RDS pricing (opens in a new tab).
- Try: run
buildandconnect, then take a manual snapshot withaws rds create-db-snapshot, delete one order, and restore the snapshot as a new database. Compare it with point-in-time recovery: which moment did each bring back? Delete the snapshot before runningdelete.