
Course 6 Β· IaC, CI/CD and FinOps
A recipe that rebuilds it all in one command
π― By the end of today
- You can explain why teams write their infrastructure as code, and the difference between "write the steps" and "write the end result".
- You can deploy, update (through a change set) and delete a CloudFormation stack from the command line, and show what drift is.
- You can compare CloudFormation and Terraform and say which one you'd pick for your platform.
- You can sketch how a code change travels to production, and pick between rolling, blue/green and canary deployments.
- You can estimate what your platform would cost per month on real AWS, and you've rebuilt it from zero in one command (project M5).
ποΈ The plan for today
| Time | What | Where |
|---|---|---|
| 0:00 (20 min) | Why infrastructure as code, CloudFormation anatomy, change sets, drift, Terraform comparison | Lecture |
| 0:20 (15 min) | CI/CD and deployment strategies | Lecture |
| 0:35 (10 min) | FinOps, DR, Well-Architected recap | Lecture |
| 0:45 (15 min) | Project M5, steps 1 and 2: read your templates, put your idea in | Project |
| 1:00 (30 min) | Steps 3 to 5: wipe, rebuild in one command, prove it | Project |
| 1:30 (20 min) | Steps 6 and 7: a change set, a drift | Project |
| 1:50 (10 min) | Break | |
| 2:00 | Step 8: freeze, check M5 pushed. Then rolling defenses, 8 minutes per group (see the Project page) | Defense |
π§± Why infrastructure as code
Six months from now, someone has opened port 22 on app-sg "for five minutes" during an incident, someone else has changed the database size from the console, and the only record of the VPC (Virtual Private Cloud, your private network) is your memory of course 3.
Nobody knows what your platform really looks like anymore.
Infrastructure as code fixes that.
You describe your cloud in text files, you keep them in Git, and a tool makes AWS match the files.
The template is like a recipe, and the running infrastructure is the cake.
If you lose the cake you bake another one, if you lose the recipe you're guessing.
Four things get better once you do this:
- You see drift. When reality differs from the code the tool tells you, you don't wait for something to break.
- Changes get reviewed. A firewall change becomes a pull request a classmate reads before it ships, and you keep a history of who changed what.
- Copies are identical. A test copy and the real thing come from the same template, so "it worked in test" means something.
- Recovery gets simple. If you lose a region you redeploy the files somewhere else, no rebuilding from screenshots at 3:00.
Write the steps, or write the end result
There are two ways to automate infrastructure, and the difference matters more than the tool you pick.
Declarative tools are idempotent, so applying the same file again is safe, that's what lets you automate changes and review them.
π CloudFormation: templates, stacks, change sets
CloudFormation is AWS's own IaC service.
You give it a template written in YAML (or JSON, another text format), and it builds a stack, all the real resources that template describes, managed as one unit.
Delete the stack and everything in it goes away, in the right order, and nothing gets left behind.
A template has three sections you'll use all the time:
Parameters: inputs you give at deploy time, like a name prefix or a size.- One template can then serve several copies of Puff.
Resources: the only required section.- Each resource has a logical ID (your nickname for it inside the template), a
Type(what to build) andProperties(how). Outputs: values the stack shows once it's built, like a VPC ID, so people and other stacks can find them.
Here's a tiny example with comments, one bucket for Puff:
AWSTemplateFormatVersion: "2010-09-09"
Description: Tiny example, one S3 bucket
Parameters:
Login: # passed at deploy time
Type: String
Description: Your EPITA login, used in the bucket name
Resources:
AssetsBucket: # logical ID, used inside the template
Type: AWS::S3::Bucket # what to create
Properties:
BucketName: !Sub "puff-assets-${Login}" # !Sub fills in ${Login}
Tags:
- Key: Project
Value: puff
Outputs:
BucketArn:
Value: !GetAtt AssetsBucket.Arn # !GetAtt reads an attribute of a resourceTwo functions do most of the work.!Ref X gives you the ID of resource X (or the value of parameter X), !GetAtt X.Attr gives you one specific attribute of it.
Every !Ref also tells CloudFormation "this depends on that", so it builds the VPC before the subnet that points at it.
When a dependency is real but invisible (a route to the internet only works once the gateway is attached), you add DependsOn by hand.
Three stack features matter in real life:
- Change sets show you what CloudFormation would add, modify or remove, before an update.
- It also tells you if a change means replacement, which deletes the resource and builds a new one. For a database that's a new, empty database, so read that column every time.
- Automatic rollback puts everything back the way it was if a deploy fails halfway, so you don't end up with half a Puff.
- Drift detection compares each resource with the template and flags anything changed by hand, like that port 22 rule.
βοΈ CloudFormation vs Terraform
Terraform (by HashiCorp) is the other big declarative tool.
You write HCL (HashiCorp Configuration Language, its own small language), run terraform plan to preview, then terraform apply to build.
The plan is the same idea as a change set.
The big difference is who runs it, AWS runs CloudFormation for you and it only speaks AWS, you run Terraform yourself and it speaks to almost every cloud and online tool.
resource "aws_vpc" "puff" {
cidr_block = "10.0.0.0/16"
tags = { Name = "puff-vpc" }
}
# terraform plan -> + aws_vpc.puff will be created
# terraform apply -> creates it and records the ID in the stateCloudFormation wins on zero setup and tight AWS integration, Terraform wins when your infrastructure goes beyond AWS.
π Want more? Side by side, and Terraform state
| CloudFormation | Terraform | |
|---|---|---|
| Who runs it | AWS runs it for you | You run it, on your laptop or in a pipeline |
| Clouds | AWS only | AWS, GCP, Azure, Datadog, GitHub, Cloudflare and thousands more through plugins called providers |
| Language | YAML or JSON with a few built-in functions | HCL, with loops, modules and expressions |
| Where it remembers what it built | Inside AWS, nothing to manage | A state file you store and lock yourself |
| Preview | Change set | terraform plan |
| Fails halfway | Rolls back by itself | Stops where it failed, you fix and re-apply |
| Drift | Drift detection when you ask | Every plan shows it |
| Reuse | Nested stacks, modules, AWS Quick Starts | A huge public library of modules |
| Licence | Free, part of AWS | BSL (a source-available licence) since 2023, OpenTofu is the open-source fork |
Terraform keeps a state file, a JSON record that maps every resource in your code to its real ID in the cloud (aws_vpc.puff is vpc-0abc...).
On each plan it refreshes that record against reality and compares it with your code.
Teams keep state remotely (an S3 bucket with locking, for example) so two people can't apply at the same time, and they guard it carefully, because state can contain passwords in plain text.
CloudFormation's version of this mapping is the Resources tab of a stack, which AWS stores for you.
π§ͺ Project M5: your platform as code, rebuilt from zero
Everything you built since course 2 was typed by hand. Today it becomes two CloudFormation templates and one script, and you prove it the hard way: you wipe everything and rebuild it in one command, in front of me at the defense.
Before you start: M4 green, source env.sh, export GROUP=gXX. Get the templates and the new checks:
# The new checks
curl -fsSL https://raw.githubusercontent.com/ricoleabricot/puff/main/starter/checks/check.sh -o checks/check.sh
# The templates, the rebuild script and the autoscaler code
for f in network.yaml app.yaml rebuild.sh scaler.py; do
curl -fsSL https://raw.githubusercontent.com/ricoleabricot/puff/main/starter/infra/$f -o infra/$f
done
chmod +x checks/check.sh infra/rebuild.sh# The new checks
curl.exe -fsSL https://raw.githubusercontent.com/ricoleabricot/puff/main/starter/checks/check.ps1 -o checks/check.ps1
# The templates, the rebuild script and the autoscaler code
foreach ($f in 'network.yaml', 'app.yaml', 'rebuild.ps1', 'scaler.py') {
curl.exe -fsSL "https://raw.githubusercontent.com/ricoleabricot/puff/main/starter/infra/$f" -o "infra/$f"
}Step 1: read your templates. Open infra/network.yaml and infra/app.yaml. Every resource is something you created by hand in M2 to M4: find each one, and write in NOTES.md the two you'd have forgotten if you had written the templates yourself.
network.yaml is your course 3 VPC: subnets, route tables, gateways, the security group chain. app.yaml is the rest: the secret, the database, logs, the execution role, the load balancer, ECS, the deployer role.
Your pager, autoscaler and CDN stay in infra/rebuild.sh as CLI commands, the same ones you typed. Moving them into a template is a good extra.
Step 2: your idea goes in. Whatever your idea needs (a schedule, a cache in front of the load balancer, a private bucket) goes into a template or into rebuild.sh / rebuild.ps1, never only in your terminal history. Add a line to your ## Idea section in NOTES.md that starts with - Built: and says what you built and where it lives.
Step 3: wipe everything. Your whole local AWS goes away. Your code stays in Git.
# Commit first: the repo is what survives
git add -A && git commit -m "M5 templates" && git push
# Delete every resource, every stack, every container
./wipe.sh# Commit first: the repo is what survives
git add -A
git commit -m "M5 templates"
git push
# Delete every resource, every stack, every container
.\wipe.ps1Step 4: rebuild in one command, and time it.
# Wait for Floci, then rebuild your whole platform
until curl -s localhost:4566 >/dev/null; do sleep 2; done
./infra/rebuild.sh | tee -a NOTES.md# Wait for Floci, then rebuild your whole platform
do { Start-Sleep 2; curl.exe -s -o NUL http://localhost:4566 } until ($LASTEXITCODE -eq 0)
$r = .\infra\rebuild.ps1
$r; $r | Add-Content NOTES.mdThe last line says Rebuilt in N s: it's in NOTES.md now. Open the app URL it prints.
Step 5: prove the rebuilt platform behaves like the old one. Your autoscaler's history was wiped with everything else, so replay the load drill.
# The crowd arrives, then leaves
aws cloudwatch put-metric-data --namespace $GROUP --metric-name Load --value 95
sleep 70
aws cloudwatch put-metric-data --namespace $GROUP --metric-name Load --value 10
sleep 70
# Every milestone, on the rebuilt platform
for m in M2 M3 M4 M5; do ./checks/check.sh $m; done | tee -a NOTES.md# The crowd arrives, then leaves
aws cloudwatch put-metric-data --namespace $env:GROUP --metric-name Load --value 95
Start-Sleep 70
aws cloudwatch put-metric-data --namespace $env:GROUP --metric-name Load --value 10
Start-Sleep 70
# Every milestone, on the rebuilt platform
$r = foreach ($m in 'M2', 'M3', 'M4', 'M5') { .\checks\check.ps1 $m }
$r; $r | Add-Content NOTES.mdStep 6: a change, the CloudFormation way. A change set shows you what will happen before it happens.
# Ask for 3 containers instead of 2, keep every other parameter
KEEP=$(aws cloudformation describe-stacks --stack-name $GROUP-app --query 'Stacks[0].Parameters[].ParameterKey' \
--output text | tr '\t' '\n' | grep -v DesiredCount | sed 's/.*/ParameterKey=&,UsePreviousValue=true/')
aws cloudformation create-change-set --stack-name $GROUP-app --change-set-name three-copies \
--use-previous-template --capabilities CAPABILITY_NAMED_IAM \
--parameters $KEEP ParameterKey=DesiredCount,ParameterValue=3
# Read it before you run it: what changes, and is anything replaced?
aws cloudformation describe-change-set --stack-name $GROUP-app --change-set-name three-copies \
--query 'Changes[].ResourceChange.[Action,LogicalResourceId,Replacement]'
# Happy with it? Run it
aws cloudformation execute-change-set --stack-name $GROUP-app --change-set-name three-copies# Ask for 3 containers instead of 2, keep every other parameter
$KEEP = (aws cloudformation describe-stacks --stack-name "$env:GROUP-app" `
--query 'Stacks[0].Parameters[].ParameterKey' --output text) -split '\s+' |
Where-Object { $_ -and $_ -ne 'DesiredCount' } |
ForEach-Object { "ParameterKey=$_,UsePreviousValue=true" }
aws cloudformation create-change-set --stack-name "$env:GROUP-app" --change-set-name three-copies `
--use-previous-template --capabilities CAPABILITY_NAMED_IAM `
--parameters $KEEP ParameterKey=DesiredCount,ParameterValue=3
# Read it before you run it: what changes, and is anything replaced?
aws cloudformation describe-change-set --stack-name "$env:GROUP-app" --change-set-name three-copies `
--query 'Changes[].ResourceChange.[Action,LogicalResourceId,Replacement]'
# Happy with it? Run it
aws cloudformation execute-change-set --stack-name "$env:GROUP-app" --change-set-name three-copiesStep 7: drift, the change nobody wrote down. Someone opens port 22 "for five minutes" during an incident.
# The hand change
APP_SG=$(aws cloudformation describe-stacks --stack-name $GROUP-network \
--query "Stacks[0].Outputs[?OutputKey=='ApiSecurityGroupId'].OutputValue" --output text)
aws ec2 authorize-security-group-ingress --group-id $APP_SG --protocol tcp --port 22 --cidr 0.0.0.0/0
# Redeploy the template: CloudFormation says nothing changed, and the rule stays
aws cloudformation deploy --stack-name $GROUP-network --template-file infra/network.yaml \
--parameter-overrides NamePrefix=$GROUP --tags Project=$GROUP
# Clean up your mess
aws ec2 revoke-security-group-ingress --group-id $APP_SG --protocol tcp --port 22 --cidr 0.0.0.0/0# The hand change
$APP_SG = aws cloudformation describe-stacks --stack-name "$env:GROUP-network" `
--query "Stacks[0].Outputs[?OutputKey=='ApiSecurityGroupId'].OutputValue" --output text
aws ec2 authorize-security-group-ingress --group-id $APP_SG --protocol tcp --port 22 --cidr 0.0.0.0/0
# Redeploy the template: CloudFormation says nothing changed, and the rule stays
aws cloudformation deploy --stack-name "$env:GROUP-network" --template-file infra/network.yaml `
--parameter-overrides "NamePrefix=$env:GROUP" --tags "Project=$env:GROUP"
# Clean up your mess
aws ec2 revoke-security-group-ingress --group-id $APP_SG --protocol tcp --port 22 --cidr 0.0.0.0/0CloudFormation only compares your template with what it remembers, not with reality. On real AWS, drift detection would flag that rule. Floci doesn't have it, which makes the point even louder: the template is the truth only if nobody touches the console.
Step 8: freeze. At the start of the defense block, everything freezes.
./checks/check.sh M5 | tee -a NOTES.md
git add -A
git commit -m "M5 freeze"
git push$r = .\checks\check.ps1 M5
$r; $r | Add-Content NOTES.md
git add -A
git commit -m "M5 freeze"
git pushπ§― If it doesn't work
- A stack fails:
aws cloudformation describe-stack-events --stack-name $GROUP-app --query 'StackEvents[?contains(ResourceStatus,`FAILED`)].[LogicalResourceId,ResourceStatusReason]'. Fix the template, delete the failed stack, runrebuild.shagain. No changes to deploy: that's fine, the stack already matches the template.rebuild.shstops at "image": Docker can't reach Floci's registry yet, wait 20 seconds afterwipe.sh.EntityAlreadyExistsoralready existsin steps 4 to 6 of the script: you ran it twice without wiping. Wipe, or delete that one resource.- The app URL doesn't answer right after the rebuild: containers start about 30 seconds after the stack is done.
πΈ On real AWS
The same two templates deploy on a real account, minus the Floci notes in comments: the app security group would reference the ALB's group, and the image would come from the ECR URI.
In the console, CloudFormation β Stacks β your stack β Events shows every resource being created, Resources links to each one, and Drift detection lists the port 22 rule as MODIFIED.
In a real team, rebuild.sh becomes a pipeline: a commit on main runs the change set, someone reads it, and it executes.
π CI/CD: from a commit to production
Deploys are risky, and a deploy from someone's laptop on a Friday evening is worse.
CI/CD takes the manual work out of it.
Continuous integration means every change pushed to Git is built and tested automatically, like a robot that checks every homework before it's handed in.
Continuous delivery means every change that passes can go live through the same automated path.
The pipeline is a few stages in a row, and each one only runs if the previous one passed:
- Build turns source code into an artifact: one packaged, versioned thing you deploy.
- For your app, a Docker image tagged with the Git commit ID (its SHA, a unique fingerprint).
- Test runs that exact artifact: unit tests, then the container against a real PostgreSQL database.
- Deploy pushes the same artifact to a test copy (staging) first, then to production, often with a human approval in between.
Build once, promote the same image everywhere.
If you rebuild for production, production runs something you never tested.
π Want more? A real pipeline for your app
Here's what a GitHub Actions pipeline for your app could look like on real AWS. Floci can run inside GitHub Actions too, a nice extra to try, but read it as a design first.123456789012 is AWS's placeholder account number for docs, and puff-app.yaml is the app template you'd get by growing today's stretch.
name: puff-api
on:
push:
branches: [main]
permissions:
id-token: write # lets the job get short-lived AWS credentials (OIDC), no stored keys
contents: read
env:
AWS_REGION: us-east-1
IMAGE: 123456789012.dkr.ecr.us-east-1.amazonaws.com/puff-api
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_DB: puff
POSTGRES_USER: puff
POSTGRES_PASSWORD: test
ports: ["5432:5432"]
steps:
- uses: actions/checkout@v4
- name: Build the artifact
run: docker build -t "$IMAGE:${{ github.sha }}" .
- name: Integration test against a real PostgreSQL
run: |
docker run -d --network host -e DB_HOST=localhost -e DB_NAME=puff \
-e DB_USER=puff -e DB_PASSWORD=test "$IMAGE:${{ github.sha }}"
sleep 5
curl -fsS localhost:8080/health
curl -fsS -X POST localhost:8080/api/messages \
-H 'Content-Type: application/json' -d '{"author":"ci","text":"hello"}'
curl -fsS localhost:8080/api/messages | grep -q hello
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/puff-ci
aws-region: ${{ env.AWS_REGION }}
- name: Push the artifact
run: |
aws ecr get-login-password | docker login --username AWS --password-stdin "${IMAGE%%/*}"
docker push "$IMAGE:${{ github.sha }}"
deploy-staging:
needs: build-and-test
runs-on: ubuntu-latest
environment: staging
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/puff-deploy-staging
aws-region: ${{ env.AWS_REGION }}
- run: |
aws cloudformation deploy --template-file puff-app.yaml \
--stack-name puff-app-staging \
--parameter-overrides Env=staging ImageTag=${{ github.sha }}
deploy-production:
needs: deploy-staging
runs-on: ubuntu-latest
environment: production # configured in GitHub to require a reviewer's approval
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/puff-deploy-production
aws-region: ${{ env.AWS_REGION }}
- run: |
aws cloudformation deploy --template-file puff-app.yaml \
--stack-name puff-app-production \
--parameter-overrides Env=production ImageTag=${{ github.sha }}Look at three things:
- the same
${{ github.sha }}image goes to both environments, - each environment has its own IAM (Identity and Access Management) role, so a staging job can't touch production,
- no AWS password or key is stored anywhere. The job gets short-lived credentials through OIDC (OpenID Connect, a way to prove "I'm this GitHub job" without a stored secret).
π Deployment strategies
Once the new image exists, you need to swap it in without anyone noticing.
There are three usual ways to do it.
- Rolling replaces your servers a few at a time.
- Blue/green builds a full second set of servers next to the live one, then moves all traffic at once.
- Canary sends a small share of traffic to the new version first, and you watch what happens.
| Rolling | Blue/green | Canary | |
|---|---|---|---|
| How | Replace servers a few at a time (an instance refresh of the ASG, the Auto Scaling group) | Build a full second fleet (green) next to the live one (blue), then switch all traffic at once | Send a small share of traffic (say 10%) to the new version, watch, then go to 100% |
| On Puff | Your ECS service replaces 1 container at a time behind your ALB | Two target groups, puff-tg-blue and puff-tg-green, the ALB listener points at one, deploying means repointing the listener | Same two target groups, the listener splits traffic 90/10, then 0/100 |
| Going back | Another rolling deploy of the old version (slow) | Point the listener back at blue (seconds) | Set the new version's share back to 0 (seconds) |
| Extra cost during the deploy | None | Double the servers for a while | A little |
| Watch out | Old and new versions run at the same time, so the database must work with both | Blue and green share one database, so both must accept its structure | You need good alarms, or you won't see the 10% failing |
On your platform, users reach your ALB, and its listener is the rule that decides where each request goes.
The listener points at a target group, which is a list of servers. Blue is the current Auto Scaling group, green is the new one, and both use the same database.
With blue/green, green gets built while blue still serves everyone, then the listener flips all traffic to green.
If something breaks you flip it back to blue, in seconds.
With canary, the same listener splits traffic by weight, 90% to blue and 10% to green, and you watch the alarms.
If they fire you set green back to 0, in seconds. If they stay quiet you move all traffic to green.
Blue/green and canary give you an instant way back by keeping the old version alive.
The database is what makes every strategy hard, because there's only one.
πΈ FinOps: knowing what you pay for
In the cloud, whoever picks the server size is spending money, often without seeing the bill.
FinOps means engineers look at cost the way they look at errors and speed.
When your group defends its Puff, "what does it cost?" will be one of my first questions.
The usual cost surprises
- NAT gateway data. You pay per hour and per GB through it, that's why your template sends S3 traffic through the free gateway endpoint.
- Idle resources. A NAT gateway, a load balancer or a database costs the same with zero visitors, so a forgotten test stack still bills all weekend.
- Oversized servers, like a big
m5.2xlargepicked "to be safe" that sits at 4% CPU for a year. - Data going out. Traffic to the internet costs per GB past a free allowance, and so does traffic between AZs and regions, traffic coming in is free.
- Forgotten leftovers. Old disk snapshots, unattached disks and machine images pile up.
- Public IPv4 addresses. Every one (your NAT's Elastic IP, the ALB's addresses) is billed per hour.
π Want more? Pricing models
| Model | What you commit to | Typical saving vs On-Demand | Use it for |
|---|---|---|---|
| On-Demand | Nothing, pay per second or hour | None | New or unpredictable workloads, everything in this course |
| Savings Plans | A \$/hour spend for 1 or 3 years, any instance type | Up to about 70% | The steady base you're sure to run next year |
| Reserved Instances | One instance type (and region) for 1 or 3 years | Similar to Savings Plans | Databases, if you want the deepest discount. Database Savings Plans exist too, 1 year, up to 20% on provisioned instances |
| Spot | Nothing, but AWS can take the server back with a 2-minute warning | Up to about 90% | Work that can be interrupted: batch jobs, CI runners, extra Auto Scaling capacity |
For a real Puff, you'd cover the two always-on API servers and the database with commitments and let Spot absorb the peaks.
π Want more? Tagging and rightsizing
You can't cut what you can't see.
A tag like Project=puff (the one you added in step 7), Environment=staging or Owner=team-name lets the billing tools split the bill.
People miss two details, a tag must be switched on as a cost allocation tag in the billing console before it appears in reports, and it only counts from that day.
Tags added by hand get forgotten, so put them in the template (CloudFormation stack tags spread to the resources) or in Terraform's defaults.
Rightsizing means matching size to real use. Look at two weeks of CloudWatch CPU (memory needs the CloudWatch agent): if the peak stays well under 40%, try one size down.
Burstable t3 servers are a good default for mostly idle services like the board app, as long as they don't run out of CPU credits.
Separate AWS accounts per team or environment are the most reliable cost split, because you don't depend on anyone adding a tag.
Exercise: price your Puff per month
Open https://calculator.aws/, pick US East (N. Virginia), and add the services of the Puff you finished in course 5.
Assume 730 hours a month and low traffic.
Compare with the table below and save the calculator's share link, you'll reuse it in your project justification.
All prices below are rough public On-Demand us-east-1 prices, rounded, so check the calculator for today's numbers.
| Item | Assumption | Approx. price | Approx. per month |
|---|---|---|---|
EC2 t3.micro Γ 2 (ASG min 2) | 730 h each | \~\$0.0104/h | \~\$15 |
| EBS gp2 8 GB Γ 2 | root volumes | \~\$0.10/GB-month | \~\$2 |
RDS PostgreSQL db.t3.micro, single-AZ | 730 h + 20 GB gp2 | \~\$0.018/h + \~\$0.115/GB-month | \~\$16 |
| Application Load Balancer | 730 h + \~1 LCU | \~\$0.0225/h + \~\$0.008/LCU-h | \~\$22 |
| NAT gateway | 730 h + a few GB | \~\$0.045/h + \~\$0.045/GB | \~\$33 |
| Public IPv4 Γ 3 | NAT EIP + 2 ALB addresses | \~\$0.005/h each | \~\$11 |
| S3 + CloudFront | a few MB, little traffic | mostly free tier | \~\$1 |
| CloudWatch alarms, SNS, Lambda | 2 alarms, a few emails, few invocations | \~\$0.10/alarm, rest free tier | \<\$1 |
| Total | \~\$100 |
(EBS is the disk attached to each server, an LCU is the ALB's unit of work.)
Look where the money goes, the NAT gateway, the ALB and public IPs make up about two thirds, the two API servers about a sixth.
What would you change if Puff hosted a side project with three users? And if it hosted 10,000?
π Disaster recovery in one table
DR (disaster recovery) is your plan for the day a whole region goes down, and two numbers define it:
- RPO (recovery point objective) is how much data you accept losing, counted in time.
- RTO (recovery time objective) is how long you accept being down.
Smaller numbers always cost more.
| Strategy | What runs in the backup region | RPO | RTO | Cost |
|---|---|---|---|---|
| Backup and restore | Nothing, only backups | Hours | Hours to a day | \$ |
| Pilot light | Data copied, the database running, app servers off | Minutes | Tens of minutes to hours | \$\$ |
| Warm standby | A small but complete copy, scaled up when needed | Seconds to minutes | Minutes | \$\$\$ |
| Multi-site (active/active) | The full stack serving traffic in both places | Near zero | Near zero | \$\$\$\$ |
Today's work helps here.
With your network.yaml and app.yaml, "restore" means deploying them in another region and loading the latest backup, you don't rebuild by hand under stress.
Many companies also copy backups to a separate AWS account, so one bad mistake (or one stolen credential) can't delete everything.
ποΈ Well-Architected recap: what you did on your platform
AWS's Well-Architected Framework is a checklist of six pillars for judging a cloud setup.
Here's how your platform scores, and it doubles as a checklist for your project justification.
| Pillar | What it asks | What you did on Puff |
|---|---|---|
| Operational excellence | Can you run and change it safely? | Network and app in CloudFormation, one-command rebuild, change sets before updates, an alarm that pages you |
| Security | Is the data and access protected? | Private subnets, chained security groups (alb, app, db), DB password in Secrets Manager injected by an execution role, a least-privilege deployer role |
| Reliability | Does it survive failures and growth? | 2 AZs, an ECS service of 2 or more behind the ALB, the kill drill (known gaps: one NAT gateway, single-AZ RDS) |
| Performance efficiency | Are you using the right resources? | CloudFront in front of the status page, your own autoscaler on a load metric, S3 gateway endpoint |
| Cost optimization | Do you pay only for what you need? | t3.micro and db.t3.micro, Project tag, monthly estimate, deleting idle stacks |
| Sustainability | Is the footprint as small as it can be? | Scale in when idle, small containers, and a wipe that leaves nothing running |
π Freeze and defense
At the start of the defense block everything freezes: each group pushes its repo with the check.sh M5 output in NOTES.md, and nobody changes the platform again.
Then you defend it in front of me, the way a platform team would: how it scales, how it stays available, how it recovers, what it costs and how it's secured.
Your pitch includes a live rebuild: ./wipe.sh, ./infra/rebuild.sh, and the app answers. Defenses run on a rolling order, 8 minutes per group. The Project page has the slot format and the grading.
π² Today's quiz
π€ Think about it
- A classmate fixes a bug by editing a security group in the console. The next morning, another teammate deploys an unrelated change to the same stack. What can happen, and what should the classmate have done after the fix?
- In your change set, the RDS database shows
Replacement: True. What do you do before executing it? - Your app's next release renames a database column. Why does that break both rolling and blue/green deployments?
- The NAT gateway is a third of your Puff bill. Name two ways to shrink that cost, and what each one costs you in security or reliability.
- Why does copying backups to another region protect you from different problems than copying them to another account?
π‘ Hints
- That's drift, the next update may put back the template's version of that resource, or fail on it. The fix belongs in the template, the same day.
- Replacement means a new, empty database. Think snapshots, and whether you really need that change.
- During any rollout, old and new code talk to one database at the same time. Look up "expand and contract" migrations.
- What do your private servers use the internet for? Endpoints, pre-built images, or a shared NAT.
- One protects against a place failing, the other against a person or a stolen credential.