
Compute, data and the 3-tier app
Course 2 · Today your group's app goes live on ECS, with a database
Today
| When | What | Where |
|---|---|---|
| 0:00 | One project all week, groups, M0 → M5, Floci | Lecture |
| 0:15 | Compute: VM, container, function. EC2, ECS, ECR | Lecture |
| 0:55 | Data: RDS, DynamoDB, S3, the 3-tier app | Lecture |
| 1:30 | M0 catch-up: setup, users, the auditor's AccessDenied | Project |
| 2:10 | M1: your app on ECS, ALB, RDS, status page, the VM way | Project |
| 3:35 | Check M1, commit, what's wrong with it | Project |

It works. It's badly built. On purpose.
Today your app goes live the naive way, so you feel in your gut why we need the next courses.

EC2 is a hotel room
Pick the size, check in, check out. Rented in about a minute, paid by the second, someone else fixes the plumbing.
Four choices to launch one
The AMIWhat it boots, like a fresh laptop. We use Amazon Linux 2023, withdnf
The instance typeThe room size. At3.microis 2 vCPUs and 1 GiB, plenty for a small app
The diskWhat storage it gets, and what survives when it dies
User dataWhat it does by itself on first boot
Apps need different rooms
| Family | Built for | Example |
|---|---|---|
T (t3, t4g) | Short bursts of CPU | A small API like yours |
M (m7i, m7g) | A bit of everything | A web app with real traffic |
C (c7i, c7g) | Raw CPU | Video encoding, batch jobs |
R (r7i, r7g) | Lots of memory | Caches, in-memory analytics |
I (i4i) | Very fast local disk | Databases you run yourself |
G, P (g5, p5) | GPUs | Machine learning inference |
Start small in T or M, measure for a week, then resize. A wrong guess costs five minutes.
Your server dies. Which files die with it?
| EBS | Instance store | EFS | S3 | |
|---|---|---|---|---|
| What it is | A disk over the network | A disk in the host | A shared folder | Files over HTTP |
| Plugged into | One instance, one AZ | That instance only | Many instances, many AZs | Nothing, an API |
| Survives a stop | Yes | No, wiped | Yes | Yes |
| Survives terminate | Only if you say so | No | Yes | Yes |
| Good for | Main disk | Scratch, caches | Shared files | Sites, uploads, backups |
Treat the instance and its disks as disposable. Anything you can't lose goes to RDS, S3 or EFS.
In a data center
| In a data center | What it became on AWS |
|---|---|
| A purchase order, weeks of delivery, a rack slot, cables | An EC2 instance in about a minute |
| VMware, Hyper-V: many VMs on one box | What EC2 is underneath |
| SAN, block storage over a dedicated network | EBS |
| NAS, shared files | EFS |
| Tomcat, JBoss, IIS application servers | Docker on EC2, for Puff |
And the backups go to tape, and the tapes go off-site.

User data: set up once, never log in
A script the instance runs once, as root, on its first boot. The cheapest automation there is.
Two ways into the box

SSH with a key pair
Port 22 open, a public IP, a key that gets copied and forgotten

Session Manager
No open port, no key. IAM decides who gets in and logs every session

You terminate your VM and launch a new one with the same user data. What survives?
Same machine, very different prices
| Model | How it works | Discount | Use it for |
|---|---|---|---|
| On-Demand | Pay per second, stop anytime | None | New or spiky work, a course project |
| Savings Plans | Promise a fixed $/hour for 1 or 3 years | Up to ~72% | The steady base |
| Reserved Instances | Promise one instance type for 1 or 3 years | Up to ~72% | Same idea, older (still common for RDS) |
| Spot | AWS's spare machines, it can take them back | Up to ~90% | Test runners, batch jobs, rendering |
Commitments come last: right-size, turn off what's idle, then commit to what's left.

A nightly job runs 2 hours and can restart from its last save. Which model?
And what happens to your deadline if no spare machine is free for an hour?
Where do the containers run?

ECS
AWS's own orchestrator, often with Fargate so there are no servers to manage

EKS
Managed Kubernetes

Docker on EC2
Today: install in user data, docker run with a restart policy
One service, a handful of instances? Kubernetes is overhead.

Alan's apps run in containers on Kubernetes, described in Terraform. Right for many services and engineers, absurd for one Flask API.

The one piece you can't rebuild from a script
Lose the database, and the messages are gone.
What "managed" buys you on RDS
BackupsA daily snapshot plus every change, kept 1 to 35 days. Rewind to any second
PatchingUpdates in a maintenance window you choose
FailoverMulti-AZ keeps a twin in another AZ. The endpoint moves to it in a minute or two
Storage and monitoringThe disk grows without downtime, metrics land in CloudWatch
Rent the caretaker, or be one
| RDS PostgreSQL | PostgreSQL on EC2 | |
|---|---|---|
| Setup | A form or one CLI command | You install and lock it down |
| Backups | Built in, rewind to any second | You script pg_dump and test restores |
| Surviving a crash | Tick the Multi-AZ box | You build replication and failover |
| Control | No superuser, limited extensions | Full root, any extension |
| Cost | Higher per hour | Lower per hour, higher in your time |
Run it yourself only when you need something RDS can't do.

DynamoDB is a giant coat check
Hand over your ticket, get your coat back instantly. But you can't ask for every red coat.
Pick by how you'll read the data
| RDS | DynamoDB | |
|---|---|---|
| Data looks like | Tables that reference each other | Items fetched by key |
| Questions | Any SQL, even ones you invent later | Only what your keys allow |
| Growing | Bigger instance, read copies | Automatic, nearly unlimited |
| Work for you | Size, connections, maintenance | Almost none |
| Good for | Business data, reporting | Sessions, carts, lookups by ID |
An insurer's members, contracts and claims: relational. A "last seen" per phone, millions of times a day: DynamoDB.
One database per shape of data
| Service | Shape | Typical use |
|---|---|---|
| Aurora | Relational, AWS storage layer | RDS with faster failover |
| ElastiCache | In-memory | Caching, sessions, rate limiting |
| Neptune | Graph | Fraud rings, recommendations |
| Timestream | Time series | Metrics, IoT sensors |
| OpenSearch | Search index | Full-text search, logs |
| Redshift | Columnar warehouse | Analytics over billions of rows |
Start with PostgreSQL. Add an engine when you can name the query it makes fast.
From compose.yaml to AWS
| On your laptop | Today on AWS | Where it ends up |
|---|---|---|
db container | RDS $GROUP-db, public | Private subnets (course 3) |
app from the Dockerfile | ECS service behind a load balancer | 2 AZs, private subnets, own autoscaler (3, 5) |
Opening index.html | S3 status page | Behind CloudFront (course 5) |
ports: 80:80 | App security group open to the world | Only the load balancer reaches the app (3) |
Password in environment: | Password in your script | Secrets Manager (course 4) |
docker compose up | You, typing CLI commands | CloudFormation (course 6) |

Hands-on
Project M1: your app on ECS, a database, a status page
✅ ./checks/check.sh M1 prints only PASS, the app answers through the ALB

It works. List five things wrong with it.
Who can reach what, where the secrets are, what happens when something dies, how you'd know.
The list we'll fix
| The sin | Fixed in |
|---|---|
| App reachable without the load balancer | Course 3 |
| Default VPC, public IPs, public database | Course 3 |
| DB password in clear in your script | Course 4 |
| Admin keys for everyone, no logs, no alarms | Course 4 |
| One container in one place | Course 5 |
| Everything typed by hand | Course 6 |

Your API sits at 5% CPU, and 80% for ten minutes every hour. Which family?
Everything from today is on the course page.
