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:00One project all week, groups, M0 → M5, FlociLecture
0:15Compute: VM, container, function. EC2, ECS, ECRLecture
0:55Data: RDS, DynamoDB, S3, the 3-tier appLecture
1:30M0 catch-up: setup, users, the auditor's AccessDeniedProject
2:10M1: your app on ECS, ALB, RDS, status page, the VM wayProject
3:35Check M1, commit, what's wrong with itProject

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, with dnf
  • The instance typeThe room size. A t3.micro is 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 CPUA small API like yours
M (m7i, m7g)A bit of everythingA web app with real traffic
C (c7i, c7g)Raw CPUVideo encoding, batch jobs
R (r7i, r7g)Lots of memoryCaches, in-memory analytics
I (i4i)Very fast local diskDatabases you run yourself
G, P (g5, p5)GPUsMachine learning inference

Start small in T or M, measure for a week, then resize. A wrong guess costs five minutes.

Game time

Pick the instance

Open it on the course page

Your server dies. Which files die with it?

EBS Instance store EFS S3
What it isA disk over the networkA disk in the hostA shared folderFiles over HTTP
Plugged intoOne instance, one AZThat instance onlyMany instances, many AZsNothing, an API
Survives a stopYesNo, wipedYesYes
Survives terminateOnly if you say soNoYesYes
Good forMain diskScratch, cachesShared filesSites, uploads, backups

Treat the instance and its disks as disposable. Anything you can't lose goes to RDS, S3 or EFS.

Game time

Storage match

Open it on the course page

In a data center

In a data center What it became on AWS
A purchase order, weeks of delivery, a rack slot, cablesAn EC2 instance in about a minute
VMware, Hyper-V: many VMs on one boxWhat EC2 is underneath
SAN, block storage over a dedicated networkEBS
NAS, shared filesEFS
Tomcat, JBoss, IIS application serversDocker 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-DemandPay per second, stop anytimeNoneNew or spiky work, a course project
Savings PlansPromise a fixed $/hour for 1 or 3 yearsUp to ~72%The steady base
Reserved InstancesPromise one instance type for 1 or 3 yearsUp to ~72%Same idea, older (still common for RDS)
SpotAWS's spare machines, it can take them backUp 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?

Game time

Pay for EC2

Open it on the course page

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.

Kubernetes

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
SetupA form or one CLI commandYou install and lock it down
BackupsBuilt in, rewind to any secondYou script pg_dump and test restores
Surviving a crashTick the Multi-AZ boxYou build replication and failover
ControlNo superuser, limited extensionsFull root, any extension
CostHigher per hourLower 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 likeTables that reference each otherItems fetched by key
QuestionsAny SQL, even ones you invent laterOnly what your keys allow
GrowingBigger instance, read copiesAutomatic, nearly unlimited
Work for youSize, connections, maintenanceAlmost none
Good forBusiness data, reportingSessions, 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
AuroraRelational, AWS storage layerRDS with faster failover
ElastiCacheIn-memoryCaching, sessions, rate limiting
NeptuneGraphFraud rings, recommendations
TimestreamTime seriesMetrics, IoT sensors
OpenSearchSearch indexFull-text search, logs
RedshiftColumnar warehouseAnalytics over billions of rows

Start with PostgreSQL. Add an engine when you can name the query it makes fast.

Game time

Pick the database

Open it on the course page

From compose.yaml to AWS

On your laptop Today on AWS Where it ends up
db containerRDS $GROUP-db, publicPrivate subnets (course 3)
app from the DockerfileECS service behind a load balancer2 AZs, private subnets, own autoscaler (3, 5)
Opening index.htmlS3 status pageBehind CloudFront (course 5)
ports: 80:80App security group open to the worldOnly the load balancer reaches the app (3)
Password in environment:Password in your scriptSecrets Manager (course 4)
docker compose upYou, typing CLI commandsCloudFormation (course 6)

Game time

Laptop to cloud

Open it on the course page

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

Steps on the course page

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 balancerCourse 3
Default VPC, public IPs, public databaseCourse 3
DB password in clear in your scriptCourse 4
Admin keys for everyone, no logs, no alarmsCourse 4
One container in one placeCourse 5
Everything typed by handCourse 6

Game time

Today's quiz

Open it on the course page

Your API sits at 5% CPU, and 80% for ten minutes every hour. Which family?

Everything from today is on the course page.