Ravindra BagaleCourses & study guides मराठी Track your progress

16. Live Project: Building a Reels App with EC2, S3 and RDS

Chala mitrano, aaj ha book cha sarvaat maja cha divas aahe! Aattaparyant aapan tukde shikle – networking, Linux, Nginx, PHP, MySQL, domain, HTTPS, S3, RDS. Aaj he sagle tukde jodun ek khara, chalnara project banvuya: Mitrano Reels – Instagram reels sarkha app. Users account banvtat, video kiwa text post upload kartat, aani feed madhe varun khali swipe karun reels baghtat. Videos S3 madhe, data RDS madhe, code EC2 var Nginx + PHP-FPM madhe, aani AWS la bolnyasathi access key nahi – IAM role. Pratyek file cha purna code dila aahe aani to php -l ne check kelela aahe. Ghabru naka, ek ek step ne jaauya – shevti tumchya domain var HTTPS sobat app live asel!

What you will learn in this chapter

  • Designing a real three-tier app on AWS: EC2 (web), S3 (media), RDS (data)
  • Preparing the S3 bucket, the IAM role and the RDS database for the app
  • Installing LEMP, Composer and the AWS SDK for PHP on EC2
  • Writing the complete app: schema, config, accounts, upload, feed API, likes and the reel UI
  • Deploying with Nginx and PHP-FPM, checking every file with php -l
  • Adding a domain and HTTPS, testing, troubleshooting and a security checklist

Concepts in this chapter

  1. 16.1Project Overview and Architecture
  2. 16.2AWS Setup: S3 Bucket, IAM Role and RDS
  3. 16.3Server Setup: LEMP, Composer and the AWS SDK for PHP
  4. 16.4Database Schema
  5. 16.5Configuration and Shared Code
  6. 16.6Accounts: Register, Login and Logout
  7. 16.7Uploading Videos and Text Posts
  8. 16.8The Feed API and Likes
  9. 16.9The Reel UI: HTML, CSS and JavaScript
  10. 16.10Deployment: Nginx, PHP Settings and Going Live
  11. 16.11Domain and HTTPS
  12. 16.12Testing and Troubleshooting
  13. 16.13Security Checklist: The Target You Will Secure

The chapter recap is at the end of the last concept page.

Chapter 16: Live project: Reels app — practice tasks

Open chapter lessons · Full guided lab: reels app security review secrets iam (not repeated here)

16.1 Scan your code for secrets

EasyIT

Why: Keys pushed to Git are found by bots in minutes.

What: Run gitleaks on a test repo.

How:

  1. git init demo && cd demo && echo 'AWS_SECRET=abc123fake' > .env && git add . && git commit -m x
  2. docker run --rm -v $PWD:/r zricethezav/gitleaks detect -s /r

Expected output: gitleaks reports a leak (or flags .env).

Hint

Add .env to .gitignore.

Answer / how to check
  1. After removing from history, scan is clean.

16.2 Limit upload file types (Node)

MediumRetail

Why: Unchecked uploads let attackers upload scripts.

What: Accept only mp4 under 50 MB with multer.

How:

  1. npm i express multer
  2. Use fileFilter checking mimetype video/mp4 and limits fileSize 50e6.
  3. curl upload a .php file and an .mp4.

Expected output: .php rejected, .mp4 accepted.

Hint

Also check the extension, not only mimetype.

Answer / how to check
  1. Server returns error for .php.

16.3 Least-privilege IAM policy (paper)

MediumHealthcare

Why: The app only needs to put/get videos in one bucket.

What: Rewrite s3:* on * to the minimum.

How:

  1. List what the app does.
  2. Allow only s3:PutObject and s3:GetObject on arn:aws:s3:::reels-lab/*.

Expected output: Policy with 2 actions and 1 resource.

Hint

No wildcard actions.

Answer / how to check
  1. IAM Policy Simulator: DeleteObject → denied.

Extended teaching notes

Why this lesson matters

Use this lesson to strengthen systems you own: understand the risk, practise safely in a lab, then write and apply the fix.

Apply the fix across stacks

Same class of bug, same idea in every language.

Java / Spring Boot

Parameterise queries, encode output, CSRF tokens, limited Actuator, dependency scanning.

ASP.NET Core

EF Core / parameterised SQL, Razor encoding, HTTPS, Data Protection.

Node.js / Express

helmet, parameterised SQL, npm audit, avoid eval and shell concat.

Python / Django / Flask / FastAPI

ORM, autoescape, pip-audit, Bandit; never shell=True with user input.

PHP / Laravel

PDO/Eloquent, Blade escaping, composer audit.

Go / Ruby

database/sql placeholders / ActiveRecord; html/template / ERB escaping; govulncheck / Brakeman.

nginx / Apache / Tomcat

Hide versions, TLS, security headers, least-open ports.

MySQL / PostgreSQL / MongoDB / Redis

Private networks, auth on, least-privilege users, no 0.0.0.0/0.

AWS / Azure / GCP

Roles not long-lived keys, private data stores, cloud audit logs on.

Mini case study

Suppose we are on a purple-team exercise for an Indian mid-size company (sample data). Red notes a technique from this lesson against a lab clone. Blue must show the control that stops it, the log that would have fired, and the ticket that hardens production. That is the standard this course trains you for.

Defender's worksheet (do this today)

  1. Write the lesson title, date and the exact lab target you are allowed to use.
  2. List three owned systems (VMs, apps, or cloud accounts) where this lesson applies.
  3. Run one safe check from the lesson on a lab system only. Paste the command and output.
  4. Write a two-sentence fix you would give a teammate.
  5. Name one related public advisory (CERT-In, CISA, NVD, or a vendor bulletin) with its date.

Indian workplace (sample data)

Suppose we are a junior analyst at Infosys, TCS, Wipro or a fintech SOC in Bengaluru/Pune. Turn this lesson into one checklist item with an owner, a due date and a place to store evidence (ticket + screenshot).

Global practice

Compare your notes with OWASP, CIS Benchmarks, NIST CSF/IR guidance or a cloud Well-Architected security question. Write five lines on what overlaps.

Everyday analogy

Explain the risk and the fix to a family member without jargon. If they can repeat the warning, you understand it well enough to teach juniors.

Key terms

  • Control: a safeguard (patch, config, process, detection).
  • Finding: a weakness backed by evidence.
  • Remediation: the fix plus how you verified it.
  • Scope: systems you have written permission to touch.
  • Least privilege: only the access the task needs.
  • Defence in depth: several layers so one failure does not end the story.

Common mistakes

  • Skipping written permission "just for a quick scan".
  • Practising on hostel, office or public targets without authorisation.
  • Collecting tool output without writing the fix.
  • Copying attack steps onto production to "verify". Defenders verify with versions, configs and patches.
  • Publishing screenshots that contain secrets, cookies or internal hostnames.

Recap

  • Evidence, fix, owner, date.
  • Own lab only.
  • Fix > spectacle.