Exercises — Module 8: AWS
Money rules before anything: (1) Set a Budget with alerts at $5/$10 TODAY, before any lab. (2) End every session with the teardown checklist at the bottom. (3) NAT Gateway and idle ALBs are the classic leaks — create late, delete first. Free tier covers most of this if you're disciplined. Install AWS CLI v2 and configure it; do at least half of these labs via CLI, not console — CLI fluency is the job.
---## Part A — Warm-Up Drills
Drill 1 — Account hygiene (one-time, non-negotiable). MFA on root; create IAM user/role for daily work via Identity Center or an admin IAM user with MFA; create the Budget + alerts; enable Cost Explorer. ✓ You never touch root again after this drill.
Drill 2 — CLI orientation. Answer with CLI only: who am I (aws sts get-caller-identity)? what region am I defaulted to? list all regions; list AZs in yours; list any running instances across the account.
✓ Four commands in your notes.
Drill 3 — IAM policy reading reps. Take three AWS-managed policies (AmazonS3ReadOnlyAccess, AmazonEC2FullAccess, PowerUserAccess) and for each, answer from the JSON: what actions? what resources? any conditions? Which would you NEVER give a CI role and why?
✓ You can read Effect/Action/Resource/Condition fluently.
Drill 4 — S3 reps. CLI only: make a bucket (unique name), upload a file, list, download to a new name, generate a presigned URL and open it in a browser, enable versioning, overwrite the file, list versions, delete bucket (must empty first — feel that). ✓ The presigned URL moment: you shared private data with zero credentials — explain how.
Drill 5 — Pricing intuition. Using the AWS pricing pages/calculator, price a month of: t3.micro on-demand vs spot; 1 NAT Gateway idle; an ALB idle; 100GB S3; 100GB data transfer OUT. Write the numbers down. ✓ You know which of those five is the surprise-bill generator (hint: two of them).
Part B — Guided Labs
Lab 1 — IAM Least-Privilege Workshop (90 min)
- Create role
s3-backup-rolefor EC2 with a custom policy: onlys3:PutObject+GetObjectonarn:...:your-bucket/backups/*. - Launch a t3.micro with that instance profile. On it:
aws s3 cpa file tobackups/(works) → to the bucket root (denied) →aws s3 lsthe bucket (denied) →aws ec2 describe-instances(denied). ✓ Three AccessDenied errors that PROVE least privilege — screenshot them; this is the IAM story you tell in interviews. - Now break-and-fix: your "app" also needs to list the backups prefix. Read the AccessDenied error, add the minimal statement (
s3:ListBucketwith a prefix condition — note it's a BUCKET-arn permission, the classic confusion), retest. - OIDC for CI: create the GitHub OIDC identity provider + a role trusting your specific repo; policy = ECR push only. Update your Module 6 workflow to
aws-actions/configure-aws-credentialswith the role ARN — delete any long-lived AWS keys from GitHub secrets. ✓sts get-caller-identityprinted from inside a workflow run, with zero stored keys.
Lab 2 — EC2 + User Data + SG Chaining (90 min)
- In your Module 4 VPC (rebuild it if torn down — good rep!), launch an instance whose user-data script installs docker and runs your app image from Docker Hub. No SSH-ing to set up — cloud-init does it.
- Debug ritual when it doesn't work first try (it won't):
ssh in → sudo cat /var/log/cloud-init-output.log. Fix, relaunch. ✓ You know where user-data logs live — worth an hour of future confusion. - Build the SG chain:
alb-sg(443/80 from world) →app-sg(8080 from alb-sg only) → laterdb-sg(5432 from app-sg only). Verify app port unreachable from your laptop directly. - Stop vs terminate: stop the instance — does the public IP survive? the EBS data? Start it, check both. Then allocate an Elastic IP, associate, stop/start again — what's different? ✓ A 5-line note on public IP vs EIP vs private IP behavior across stops.
Lab 3 — ALB + 2 Targets + Zero-Downtime (90 min)
- Two app instances (same user-data) in two AZs' subnets. Target group with health check
/health, both registered. ALB across both public subnets → listener 80 → target group. - Curl the ALB DNS repeatedly — alternating instance hostnames.
- Kill the app process on one instance; watch the target go unhealthy in the console; confirm curls now hit only the survivor — zero errors client-side. Restart; watch it rejoin. ✓ Health-check-driven failover, witnessed. This is the mechanism behind every zero-downtime deploy.
- Path routing: add a listener rule
/api/*→ a second target group (reuse an instance on another port). Bonus: request a free ACM cert if you own a domain and add HTTPS. - Teardown the ALB when done (idle ALB ≈ $16+/mo).
Lab 4 — ECS Fargate End-to-End (2–3 h) — the reference deployment
- ECR repo (scan-on-push); push your image from CI via the Lab 1 OIDC role.
- Task definition: your image, 0.25 vCPU/0.5GB, port 8080, logs to CloudWatch (awslogs driver), a task role with only what the app needs, DB password from Secrets Manager (
secrets:field, not env plaintext). - Cluster + Service: desired 2, private subnets, app-sg, attached to the Lab 3 ALB target group. Wait for steady state; curl the ALB. ✓ Containers with no public IPs serving internet traffic through the ALB — narrate the packet path (Module 4 final exam, live).
- Deploy a new version: push new tag from CI →
aws ecs update-service --force-new-deployment(or new task-def revision). Watch the rolling replacement in the console Events tab with your curl loop running. - Kill a task by hand — ECS replaces it (reconciliation, AWS edition). Then enable the deployment circuit breaker, ship an image with a failing health check, and watch automatic rollback. ✓ Both self-healing and auto-rollback observed. Screenshot the events timeline.
- Read your app logs in CloudWatch Logs; run one Logs Insights query (count by status if your logs are JSON — Module 10 preview).
Lab 5 — Lambda Trio (90 min)
- S3-triggered: bucket + Lambda (Python) that logs object key/size on upload. Upload files, read CloudWatch logs. Break it (raise an exception), find the error + stack trace in logs, check the Errors metric.
- Cron: EventBridge schedule → Lambda that posts "heartbeat" to a Slack/Discord webhook. (You'll upgrade this in Module 11 to the dev-instance stopper.)
- Cold start feel: invoke after 20 idle minutes and immediately again; compare durations in the logs (Init duration line). ✓ You can say from experience what a cold start costs and where Lambda fits vs containers.
Lab 6 — CloudFront + Private S3 (60 min)
- Static site (index.html) in a private bucket (Block Public Access ON — leave it on forever).
- CloudFront distribution with Origin Access Control; bucket policy allowing only that OAC. Site loads via the CloudFront domain; direct S3 URL gives AccessDenied. ✓ The private-bucket test passing is the security point of the whole lab.
- Update index.html, observe stale cache, fix once with an invalidation and once "properly" (versioned filename). Note response header
x-cache: Hit/Misswhile testing.
Part C — Challenges
C1 — The audit script (CLI or console). Produce, for your account: all SGs with 0.0.0.0/0 on port 22; unattached EBS volumes; unassociated Elastic IPs (these bill!); untagged instances. (This becomes a boto3 script in Module 11.)
C2 — Spot experiment. Launch a spot instance at ~1/4 the on-demand price; check its interruption notice endpoint (curl http://169.254.169.254/latest/meta-data/spot/instance-action). Name two workloads you'd run on spot and one you never would.
C3 — Metadata service exploration. From any instance: query IMDSv2 (token dance!) for instance-id, AZ, IAM role creds expiry. Explain why IMDSv1 was an SSRF goldmine and verify your instances enforce v2.
C4 — Cross-account thinking (paper). Your company adds a staging account. Sketch: how CI deploys to both, how humans access each, where images live. (Role assumption is the answer — write the trust-policy shape.)
C5 — The bill autopsy. After a week of labs, open Cost Explorer grouped by service. Identify your top 3 costs and one thing you'd do differently. Attach the screenshot to your notes — cost awareness is a hiring signal.
Part D — Break & Fix Scenarios
D1 — 502 from the ALB. Stop the app (leave the instance up). Curl → 502/unhealthy target. Walk the chain: target health → SG from ALB to target → app listening (ss)? Fix at the right layer.
D2 — AccessDenied roulette. Remove one permission from your ECS task role (the Secrets Manager read). Redeploy — tasks fail to start. Find the REAL error (service events → stopped task's stopped-reason) and restore minimally.
D3 — The unreachable "public" instance. Launch with public IP but into the PRIVATE subnet (or public subnet with the wrong route table association). SSH times out. Diagnose with the Module 4 playbook: it's always IP/route/SG/NACL — find which.
D4 — Secrets in plaintext. "Discover" a DB password as a plain env var in a task definition (put it there yourself). Remediate: move to Secrets Manager, rotate the actual password, redeploy, and write the 3-step incident note.
D5 — Region confusion. Create a bucket in us-east-1, try to reach it with CLI defaulted to eu-west-1 expecting resources you "can't find." Recognize the everyone-does-it-once symptom; fix with --region/profiles.
Teardown Checklist (run after EVERY session)
NAT Gateways → Elastic IPs (release!) → ALBs → ECS services (desired 0, then delete) → EC2 instances → CloudFront (disable, then delete) → unattached EBS/snapshots you made → check Billing tomorrow.
Part E — Interview Rehearsal (out loud)
- Design a highly-available web app on AWS — whiteboard VPC to CDN, justify each choice.
- IAM user vs role; how does an EC2 app get credentials without keys on disk? How does CI?
- ALB vs NLB; what happens when a target fails its health check?
- ECS vs EKS vs Lambda — pick per scenario, with the trade-off you're accepting.
- A task/instance "can't access S3" — your diagnosis order.
- Region vs AZ; what does Multi-AZ actually buy and cost?
- Tell me about a time you controlled cloud costs (use your Budget + C5 autopsy + teardown discipline — it's a real, tellable story now).
Done when
Lab 1's three AccessDenied screenshots exist, Lab 4's circuit-breaker rollback was witnessed, the teardown checklist is muscle memory, next-day billing shows ≈$0, and E1's whiteboard flows end to end.
