Cloud and deployment · Intermediate · 28 min
Run a managed PostgreSQL database on Amazon RDS
By Padding · Updated 18 Nov 2026
Ubuntu 26.04 · AWS CLI 2.42.4 · RDS for PostgreSQL 18.6
You will have a PostgreSQL 18 database on Amazon RDS in private subnets, reachable only from your app servers over verified TLS, with its password held in Secrets Manager, a manual snapshot taken and a clean way to delete it all.
On this page
Running PostgreSQL yourself means you own the patching, the backups, the disk that fills up at 3 a.m. and the restore you have never rehearsed. Amazon RDS takes those jobs off you: AWS runs the server, applies minor version upgrades in a window you choose, keeps automated backups you can restore to any second inside the retention period, and gives you a single DNS name to connect to. You still own who can reach the database, how they prove who they are, and what it costs.
In this tutorial you build a small, production-shaped RDS for PostgreSQL 18 instance from the AWS CLI:
- a VPC with two private subnets for the database (no route to the internet) and one public subnet for an app server;
- a security group that admits port 5432 only from servers carrying your app's security group, never from an IP range;
- a parameter group that refuses unencrypted connections and logs every query slower than half a second;
- an instance whose master password is generated by RDS and kept in AWS Secrets Manager, so it never appears in your shell history or on the command line;
- a connection from the app server with
sslmode=verify-fulland the RDS certificate bundle, so psql checks it is talking to your database and not something in between; - a manual snapshot, a look at the automated backup settings, and a deletion that keeps a final snapshot.
Everything is named rds-demo-..., and your working files live in ~/rds-demo. Fences are labelled On your laptop or On the app instance, because the connection step runs on a server inside the VPC.
Step 1 · Install the AWS CLI and confirm the account
On your laptop. Install curl, unzip and jq, then version 2.42.4 of the AWS CLI from Amazon's versioned installer. uname -m prints x86_64 or aarch64, which matches Amazon's file names:
sudo apt update
sudo apt install -y curl unzip jq ca-certificates
AWS_CLI_VERSION=2.42.4
cd "$(mktemp -d)"
curl -fsSLo awscliv2.zip "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m)-${AWS_CLI_VERSION}.zip"
unzip -q -o awscliv2.zip
sudo ./aws/install
aws --versionIf the AWS CLI is already installed, the installer stops and says so; run sudo ./aws/install --update instead. The CLI does not get updates from apt, so to upgrade later you run the same commands with a newer version number. The zip is large, so on a prepaid mobile bundle download it once over Wi-Fi and keep it.
Point the CLI at your sandbox account. If you use a named profile, run export AWS_PROFILE=<your-sandbox-profile> first (replace the placeholder); /tutorials/set-up-the-aws-cli-with-sso-and-named-profiles shows how to set one up. Then check who you are:
aws sts get-caller-identity --query Account --output textCheck it worked
aws --version starts with aws-cli/2.42.4, and the last command prints the 12-digit ID of your sandbox account. If it prints a different account, stop and fix your profile before you create anything.
Step 2 · Build a VPC with private subnets for the database
An RDS instance lives in a DB subnet group, and that group needs subnets in at least two Availability Zones, even for a single-AZ instance. That way RDS has somewhere to move the database if you later turn on Multi-AZ. The two database subnets get no route to the internet. A third, public subnet holds the app server you connect from.
On your laptop. Create the working folder and a demo.env file that remembers the Region and every ID, so a new terminal can pick them up with . ./demo.env:
mkdir -p ~/rds-demo
cd ~/rds-demo
cat > demo.env <<'EOF'
export AWS_REGION=eu-west-2
export PG_VERSION=18.6
EOF
. ./demo.envThe examples use eu-west-2 (London). Any Region works if you use it everywhere. If you are in Africa and your account has the Cape Town Region (af-south-1) turned on, it is closer to you and your users, so queries from an app hosted nearby come back faster. It is an opt-in Region, and prices differ from Region to Region.
Create the VPC, turn on DNS hostnames (RDS endpoints are DNS names), and pick the first two Availability Zones:
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.20.0.0/16 \
--tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=rds-demo}]' \
--query Vpc.VpcId --output text)
aws ec2 modify-vpc-attribute --vpc-id "$VPC_ID" --enable-dns-hostnames '{"Value":true}'
AZ_A=$(aws ec2 describe-availability-zones --filters Name=zone-type,Values=availability-zone \
--query 'AvailabilityZones[0].ZoneName' --output text)
AZ_B=$(aws ec2 describe-availability-zones --filters Name=zone-type,Values=availability-zone \
--query 'AvailabilityZones[1].ZoneName' --output text)
echo "VPC $VPC_ID in $AZ_A and $AZ_B"Add the two private subnets and the public one:
PRIVATE_A=$(aws ec2 create-subnet --vpc-id "$VPC_ID" --cidr-block 10.20.1.0/24 \
--availability-zone "$AZ_A" --query Subnet.SubnetId --output text)
PRIVATE_B=$(aws ec2 create-subnet --vpc-id "$VPC_ID" --cidr-block 10.20.2.0/24 \
--availability-zone "$AZ_B" --query Subnet.SubnetId --output text)
PUBLIC_A=$(aws ec2 create-subnet --vpc-id "$VPC_ID" --cidr-block 10.20.0.0/24 \
--availability-zone "$AZ_A" --query Subnet.SubnetId --output text)Only the public subnet gets a route to an internet gateway. The private subnets stay on the VPC's main route table, which knows only the VPC's own 10.20.0.0/16 range:
IGW_ID=$(aws ec2 create-internet-gateway --query InternetGateway.InternetGatewayId --output text)
aws ec2 attach-internet-gateway --internet-gateway-id "$IGW_ID" --vpc-id "$VPC_ID"
PUBLIC_RT=$(aws ec2 create-route-table --vpc-id "$VPC_ID" --query RouteTable.RouteTableId --output text)
aws ec2 create-route --route-table-id "$PUBLIC_RT" --destination-cidr-block 0.0.0.0/0 --gateway-id "$IGW_ID"
PUBLIC_ASSOC=$(aws ec2 associate-route-table --route-table-id "$PUBLIC_RT" \
--subnet-id "$PUBLIC_A" --query AssociationId --output text)
cat >> demo.env <<EOF
export VPC_ID=$VPC_ID PRIVATE_A=$PRIVATE_A PRIVATE_B=$PRIVATE_B PUBLIC_A=$PUBLIC_A
export IGW_ID=$IGW_ID PUBLIC_RT=$PUBLIC_RT PUBLIC_ASSOC=$PUBLIC_ASSOC
EOFCheck it worked
aws ec2 describe-subnets --filters Name=vpc-id,Values=$VPC_ID --query 'Subnets[].[CidrBlock,AvailabilityZone]' --output text lists three subnets: 10.20.1.0/24 and 10.20.2.0/24 in two different zones, and 10.20.0.0/24. cat demo.env shows every ID you just created.
Step 3 · Let only the app reach the database
A common way databases get exposed is port 5432 opened to 0.0.0.0/0 "just for a moment". Instead of allowing an IP range, you create two security groups. rds-demo-app has no rules of its own: it is a label you attach to app servers. rds-demo-db allows PostgreSQL only from resources carrying that label, so a new app server gets access by joining the group, and nothing else in the VPC gets in.
On your laptop:
cd ~/rds-demo
. ./demo.env
APP_SG=$(aws ec2 create-security-group --group-name rds-demo-app \
--description "rds-demo app servers" --vpc-id "$VPC_ID" --query GroupId --output text)
DB_SG=$(aws ec2 create-security-group --group-name rds-demo-db \
--description "rds-demo PostgreSQL, from app servers only" --vpc-id "$VPC_ID" --query GroupId --output text)
aws ec2 authorize-security-group-ingress --group-id "$DB_SG" \
--ip-permissions "IpProtocol=tcp,FromPort=5432,ToPort=5432,UserIdGroupPairs=[{GroupId=$APP_SG,Description=app-servers}]"
echo "export APP_SG=$APP_SG DB_SG=$DB_SG" >> demo.envNow tell RDS which subnets it may use. Name only the two private subnets:
aws rds create-db-subnet-group --db-subnet-group-name rds-demo-private \
--db-subnet-group-description "rds-demo private subnets" \
--subnet-ids "$PRIVATE_A" "$PRIVATE_B" \
--query 'DBSubnetGroup.Subnets[].SubnetIdentifier' --output textWhen you name a subnet group other than default, RDS makes the instance private unless you ask otherwise. You still pass --no-publicly-accessible in a later step so the intent is written down.
Check it worked
The subnet group command prints the two private subnet IDs and not the public one. This query prints the ID of rds-demo-app, which is the only source allowed into the database group:
aws ec2 describe-security-groups --group-ids "$DB_SG" \
--query 'SecurityGroups[0].IpPermissions[0].UserIdGroupPairs[].GroupId' --output textIf you see an IpRanges entry on rds-demo-db when you run aws ec2 describe-security-groups --group-ids "$DB_SG", someone added a CIDR rule; remove it.
Step 4 · Write a parameter group that forces TLS and logs slow queries
You cannot edit postgresql.conf on RDS. Server settings live in a DB parameter group, and the default group for each family is read-only. Create your own for the postgres18 family. First confirm that 18.6 is offered in your Region and which family it belongs to:
aws rds describe-db-engine-versions --engine postgres --engine-version "$PG_VERSION" \
--query 'DBEngineVersions[0].[EngineVersion,DBParameterGroupFamily]' --output textThat prints 18.6 and postgres18. If it prints nothing, pick a version from aws rds describe-db-engine-versions --engine postgres --query "DBEngineVersions[?starts_with(EngineVersion, '18')].EngineVersion" --output text, and change PG_VERSION in demo.env.
On your laptop. Create the group and set two parameters:
rds.force_ssl = 1rejects any connection that is not encrypted. It is already the default on PostgreSQL 15 and later, but writing it into your own group means nobody can switch it off by swapping parameter groups without it showing up in review.log_min_duration_statement = 500writes every statement that takes longer than 500 ms to the PostgreSQL log, with its duration. That is your first tool when the app feels slow.
aws rds create-db-parameter-group --db-parameter-group-name rds-demo-pg18 \
--db-parameter-group-family postgres18 \
--description "rds-demo: force TLS, log slow queries" \
--query 'DBParameterGroup.DBParameterGroupName' --output text
aws rds modify-db-parameter-group --db-parameter-group-name rds-demo-pg18 \
--parameters "ParameterName=rds.force_ssl,ParameterValue=1,ApplyMethod=immediate" \
"ParameterName=log_min_duration_statement,ParameterValue=500,ApplyMethod=immediate"Both parameters are dynamic, so immediate applies them without a reboot. If you attach a new group to an instance that is already running, RDS still needs one reboot to pick up the group itself.
Check it worked
Read back only the parameters you changed. The command prints two lines, log_min_duration_statement 500 and rds.force_ssl 1:
aws rds describe-db-parameters --db-parameter-group-name rds-demo-pg18 --source user \
--query 'sort_by(Parameters, &ParameterName)[].[ParameterName,ParameterValue]' --output textStep 5 · Create the instance with its password in Secrets Manager
Before you run this, know what bills. An RDS instance is charged for every hour it exists, plus its storage, plus backup storage (automated backups and manual snapshots), plus data transfer out. Manual snapshots keep billing after the instance is gone until you delete them, and the managed secret is charged per month by Secrets Manager. On the free side, AWS says (checked 26 November 2026) that new customers get sign-up credits and a Free plan of up to six months that covers db.t3.micro and db.t4g.micro instances, and accounts created before 15 July 2025 keep the older 12-month free tier for select instances. Read the current terms at aws.amazon.com/rds/free before you rely on them, and run the clean-up step when you finish.
The command below asks for a db.t4g.micro (Graviton, two vCPUs, 1 GiB of memory), 20 GiB of encrypted gp3 storage, one Availability Zone and seven days of automated backups. Three flags do the security work:
--manage-master-user-passwordmakes RDS generate the master password and store it in Secrets Manager, encrypted with theaws/secretsmanagerkey. You never type it, so it never lands in shell history, CI logs or a process list. RDS rotates it every seven days by default.--ca-certificate-identifier rds-ca-rsa2048-g1pins the certificate authority your client will trust in the next step. It is the current default, and naming it means a change of default does not surprise you.--deletion-protectionmakesdelete-db-instancefail until you turn it off, which saves you from a wrong identifier in a script.
On your laptop:
cd ~/rds-demo
. ./demo.env
aws rds create-db-instance \
--db-instance-identifier rds-demo-db \
--engine postgres --engine-version "$PG_VERSION" \
--db-instance-class db.t4g.micro \
--allocated-storage 20 --storage-type gp3 --storage-encrypted \
--db-name appdb --master-username appadmin \
--manage-master-user-password \
--db-subnet-group-name rds-demo-private \
--vpc-security-group-ids "$DB_SG" \
--db-parameter-group-name rds-demo-pg18 \
--no-publicly-accessible --no-multi-az \
--ca-certificate-identifier rds-ca-rsa2048-g1 \
--backup-retention-period 7 --preferred-backup-window 01:00-01:30 \
--preferred-maintenance-window sun:02:00-sun:02:30 \
--copy-tags-to-snapshot --deletion-protection \
--tags Key=project,Value=rds-demo \
--query 'DBInstance.DBInstanceStatus' --output textIt prints creating. The backup and maintenance windows are in UTC; pick hours when your users are asleep. For a production database you would add --multi-az, which keeps a standby in a second zone and roughly doubles the instance cost.
Wait for the instance. This usually takes 5 to 15 minutes, and the command returns when the status is available:
aws rds wait db-instance-available --db-instance-identifier rds-demo-dbSave the endpoint and the secret's ARN:
DB_HOST=$(aws rds describe-db-instances --db-instance-identifier rds-demo-db \
--query 'DBInstances[0].Endpoint.Address' --output text)
SECRET_ARN=$(aws rds describe-db-instances --db-instance-identifier rds-demo-db \
--query 'DBInstances[0].MasterUserSecret.SecretArn' --output text)
echo "export DB_HOST=$DB_HOST" >> demo.env
echo "export SECRET_ARN='$SECRET_ARN'" >> demo.env
echo "$DB_HOST"The ARN contains a ! (...:secret:rds!db-...), which is why it is saved in single quotes.
Check it worked
This prints one line of settings:
aws rds describe-db-instances --db-instance-identifier rds-demo-db \
--query 'DBInstances[0].[DBInstanceStatus,EngineVersion,PubliclyAccessible,StorageEncrypted,DeletionProtection,MasterUserSecret.SecretStatus]' \
--output textOn your account you see something like available 18.6 False True True active. The endpoint looks like rds-demo-db.<random>.eu-west-2.rds.amazonaws.com. If PubliclyAccessible is True, delete the instance and check the subnet group name you passed.
Step 6 · Connect from an app server with verify-full
The database has no public address, so you connect from a server inside the VPC that carries the rds-demo-app group. If you do not have one yet, launch a small Ubuntu 26.04 instance into the public subnet. /tutorials/launch-an-ec2-instance-and-connect explains key pairs and SSH in detail. Replace <your-key-pair> with the name of your key pair in this Region.
On your laptop:
cd ~/rds-demo
. ./demo.env
MY_IP=$(curl -fsS -4 https://checkip.amazonaws.com)
SSH_SG=$(aws ec2 create-security-group --group-name rds-demo-ssh \
--description "rds-demo SSH from my IP" --vpc-id "$VPC_ID" --query GroupId --output text)
aws ec2 authorize-security-group-ingress --group-id "$SSH_SG" --protocol tcp --port 22 --cidr "${MY_IP}/32"
AMI_ID=$(aws ssm get-parameter \
--name /aws/service/canonical/ubuntu/server/26.04/stable/current/amd64/hvm/ebs-gp3/ami-id \
--query Parameter.Value --output text)
APP_INSTANCE=$(aws ec2 run-instances --image-id "$AMI_ID" --instance-type t3.micro \
--key-name <your-key-pair> --subnet-id "$PUBLIC_A" --associate-public-ip-address \
--security-group-ids "$SSH_SG" "$APP_SG" --metadata-options HttpTokens=required \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=rds-demo-app}]' \
--query 'Instances[0].InstanceId' --output text)
echo "export SSH_SG=$SSH_SG APP_INSTANCE=$APP_INSTANCE" >> demo.env
aws ec2 wait instance-running --instance-ids "$APP_INSTANCE"
aws ec2 describe-instances --instance-ids "$APP_INSTANCE" \
--query 'Reservations[0].Instances[0].PublicIpAddress' --output textThe instance is billed by the hour, and so is its public IPv4 address. SSH in with ssh -i <path-to-your-key> ubuntu@<public-ip>.
On the app instance. Install the PostgreSQL 18 client and download the RDS certificate bundle for your Region. The bundle holds the RDS root certificates; psql uses it to check that the server's certificate was signed by RDS and that its name matches the host you asked for. Change RDS_REGION if you used a different Region:
sudo apt update
sudo apt install -y postgresql-client-18 curl openssl
RDS_REGION=eu-west-2
mkdir -p ~/rds-demo
curl -fsSLo ~/rds-demo/rds-ca.pem \
"https://truststore.pki.rds.amazonaws.com/${RDS_REGION}/${RDS_REGION}-bundle.pem"
grep -c 'BEGIN CERTIFICATE' ~/rds-demo/rds-ca.pem
psql --versionThe bundle contains a few root certificates, one per CA type. Trust only this file, not intermediate certificates you find elsewhere: RDS rotates the server certificate below the root automatically.
On your laptop. Read the generated password. It appears on your screen, so do this where nobody is looking over your shoulder, and run clear afterwards:
cd ~/rds-demo
. ./demo.env
aws secretsmanager get-secret-value --secret-id "$SECRET_ARN" \
--query SecretString --output text | jq -r .password
echo "$DB_HOST"In a real app you would not copy the password at all. Give the app server's IAM role secretsmanager:GetSecretValue on this one ARN and have the app read the secret at start-up, so it picks up each rotation; /tutorials/store-app-secrets-in-aws-secrets-manager-and-parameter-store covers that pattern.
On the app instance. Set DB_HOST to the endpoint your laptop printed (replace the placeholder), then connect. psql prompts for the password; paste it there, never into the command:
DB_HOST=<endpoint-from-your-laptop>
psql "host=$DB_HOST port=5432 dbname=appdb user=appadmin sslmode=verify-full sslrootcert=$HOME/rds-demo/rds-ca.pem"At the appdb=> prompt, confirm the version and the encryption, and run one deliberately slow statement so the slow-query log has something to show:
SELECT version();
SELECT ssl, version AS tls_version FROM pg_stat_ssl WHERE pid = pg_backend_pid();
SELECT pg_sleep(0.6);
\qNow prove the parameter group is doing its job. This tries to connect without encryption:
psql "host=$DB_HOST port=5432 dbname=appdb user=appadmin sslmode=disable"Check it worked
The grep -c prints a small number (3 or so), and psql --version prints psql (PostgreSQL) 18. and a minor version. In the psql session, the banner shows a line like SSL connection (protocol: TLSv1.3, ...), version() starts with PostgreSQL 18.6, and the pg_stat_ssl row shows t and TLSv1.3. The sslmode=disable attempt fails straight away, without asking for a password, with a FATAL: no pg_hba.conf entry error that ends with no encryption.
If psql fails with server certificate for "..." does not match host name, you used an IP address or a custom DNS name instead of the RDS endpoint. If it hangs and times out, the instance is missing the rds-demo-app group.
Back on your laptop, the slow statement is in the newest PostgreSQL log file, as a line containing duration: 60 followed by milliseconds and pg_sleep(0.6):
LOG_FILE=$(aws rds describe-db-log-files --db-instance-identifier rds-demo-db \
--query 'DescribeDBLogFiles[-1].LogFileName' --output text)
aws rds download-db-log-file-portion --db-instance-identifier rds-demo-db \
--log-file-name "$LOG_FILE" --output text | grep -F 'duration:'Step 7 · Take a manual snapshot and read the backup settings
RDS gives you two kinds of backup, and they behave differently:
- Automated backups are a daily snapshot taken in your backup window plus transaction logs. Together they let you restore to any second within the retention period (7 days here, 35 at most). They are deleted when the retention period passes, and by default when you delete the instance.
- Manual snapshots are taken when you ask and kept until you delete them, even after the instance is gone. Take one before every risky change: a major version upgrade, a big migration, a parameter change you are not sure about.
On your laptop:
cd ~/rds-demo
. ./demo.env
aws rds create-db-snapshot --db-instance-identifier rds-demo-db \
--db-snapshot-identifier rds-demo-before-migration \
--query 'DBSnapshot.Status' --output text
aws rds wait db-snapshot-available --db-snapshot-identifier rds-demo-before-migrationOn a single-AZ instance, every snapshot pauses I/O briefly (seconds to a few minutes, depending on size and class), so take them at a quiet time. Snapshots after the first are incremental. Now read the automated backup settings and the latest point you could restore to:
aws rds describe-db-instances --db-instance-identifier rds-demo-db \
--query 'DBInstances[0].{Retention: BackupRetentionPeriod, Window: PreferredBackupWindow, LatestRestorable: LatestRestorableTime}'
aws rds describe-db-snapshots --db-instance-identifier rds-demo-db \
--query 'DBSnapshots[].[DBSnapshotIdentifier,SnapshotType,Status]' --output textLatestRestorableTime is usually within five minutes of now. To go back in time you would run aws rds restore-db-instance-to-point-in-time, which always creates a new instance with a new endpoint; your app then has to point at it. Practise that once on a sandbox before you need it.
Check it worked
The first command prints creating on AWS, and the waiter returns once the snapshot is ready (a few minutes for a new, nearly empty database). The settings show "Retention": 7 and "Window": "01:00-01:30". The snapshot list includes a line rds-demo-before-migration manual available, and after the first backup window has passed, an automated snapshot too.
Step 8 · Delete the instance with a final snapshot and clean up
On the app instance, if you launched one, log out. On your laptop, terminate it and delete its SSH group first, because a VPC cannot be deleted while an instance is still in it:
cd ~/rds-demo
. ./demo.env
aws ec2 terminate-instances --instance-ids "$APP_INSTANCE" --query 'TerminatingInstances[0].CurrentState.Name' --output text
aws ec2 wait instance-terminated --instance-ids "$APP_INSTANCE"
aws ec2 delete-security-group --group-id "$SSH_SG"Next, delete the database. Deletion protection must be turned off first. --final-db-snapshot-identifier makes RDS take one last snapshot before it removes the instance, so a mistaken delete is recoverable. Deleting the instance also deletes its automated backups and its managed secret; if you ever restore from the final snapshot, you set up password management again on the new instance.
The commands below permanently delete the instance named rds-demo-db. Check that the name is yours before you run them:
cd ~/rds-demo
. ./demo.env
aws rds modify-db-instance --db-instance-identifier rds-demo-db \
--no-deletion-protection --apply-immediately \
--query 'DBInstance.DBInstanceIdentifier' --output text
aws rds delete-db-instance --db-instance-identifier rds-demo-db \
--final-db-snapshot-identifier rds-demo-final \
--query 'DBInstance.DBInstanceStatus' --output text
aws rds wait db-instance-deleted --db-instance-identifier rds-demo-dbThe delete prints deleting, and the waiter can take 10 minutes or more. Now confirm the final snapshot exists:
aws rds describe-db-snapshots --db-snapshot-identifier rds-demo-final \
--query 'DBSnapshots[0].[DBSnapshotIdentifier,Status]' --output textBoth manual snapshots keep billing for storage until you delete them. For this demo nothing in them is worth keeping, so delete them, then the parameter group, the subnet group and the network. A security group can take a few minutes to free up after RDS releases its network interface; if delete-security-group reports DependencyViolation, wait a minute and run it again:
aws rds delete-db-snapshot --db-snapshot-identifier rds-demo-final --query 'DBSnapshot.Status' --output text
aws rds delete-db-snapshot --db-snapshot-identifier rds-demo-before-migration --query 'DBSnapshot.Status' --output text
aws rds delete-db-parameter-group --db-parameter-group-name rds-demo-pg18
aws rds delete-db-subnet-group --db-subnet-group-name rds-demo-private
aws ec2 delete-security-group --group-id "$DB_SG"
aws ec2 delete-security-group --group-id "$APP_SG"
aws ec2 disassociate-route-table --association-id "$PUBLIC_ASSOC"
aws ec2 delete-route-table --route-table-id "$PUBLIC_RT"
aws ec2 detach-internet-gateway --internet-gateway-id "$IGW_ID" --vpc-id "$VPC_ID"
aws ec2 delete-internet-gateway --internet-gateway-id "$IGW_ID"
aws ec2 delete-subnet --subnet-id "$PUBLIC_A"
aws ec2 delete-subnet --subnet-id "$PRIVATE_A"
aws ec2 delete-subnet --subnet-id "$PRIVATE_B"
aws ec2 delete-vpc --vpc-id "$VPC_ID"
cd ~
rm -rf ~/rds-demoOn the app instance there is nothing left to remove: terminating it deleted its disk.
Check it worked
aws rds describe-db-instances --db-instance-identifier rds-demo-db fails with DBInstanceNotFound, aws rds describe-db-snapshots --query "DBSnapshots[?starts_with(DBSnapshotIdentifier, 'rds-demo')]" prints [], and aws ec2 describe-vpcs --filters Name=tag:Name,Values=rds-demo --query Vpcs prints []. In the Billing console, the RDS line for the Region stops growing from the next day.
Next steps
- Go deeper on the network side, including how security groups and network ACLs combine: control traffic in AWS with security groups and network ACLs.
- Compare with running PostgreSQL yourself, so you know what RDS is doing for you: install PostgreSQL 18 on Ubuntu 26.04.
- Before you put real data on RDS, restore the final snapshot of a sandbox instance into a new instance and time how long your app takes to switch to it.
Related tutorials
- Control traffic in AWS with security groups and network ACLsYou will build a three-tier set of security groups that chain by group ID, add a network ACL that blocks one abusive address range at the subnet edge, and run a query that lists every rule open to the whole internet.
- How to Install PostgreSQL 18 on Ubuntu 26.04 and Create Your First DatabaseYou will install PostgreSQL 18 from the official PostgreSQL apt repository, create a database and a user for your app, and connect to it with a password.
- How to Launch an AWS EC2 Instance and Connect with SSHYou will launch an Ubuntu 26.04 LTS virtual server on AWS EC2 with the AWS CLI, allow SSH from your own address only, log in with a new key pair, and then terminate everything so it stops billing.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials