Chapter 2: Prerequisites¶
Don't start building until everything in this chapter is in place. Most of the incident in Chapter 1 came from skipping decisions, not from lacking tools.
2.1 Knowledge you need (or need to brush up on)¶
| Area | Enough to… |
|---|---|
| Linux shell | Navigate, edit files, read logs, manage services (systemctl), use sudo safely |
| SSH | Generate/use key pairs, understand authorized_keys, sshd_config basics |
| Networking basics | Public vs private IPs, CIDR (/32, /16, 0.0.0.0/0), ports, DNS (A, CNAME), what "listening on 0.0.0.0" means |
| Docker & Compose | Images vs containers, volumes, networks, ports: vs expose:, env_file, docker compose up/down/logs/exec |
| PostgreSQL | Roles vs users, superuser vs ordinary roles, pg_hba.conf, psql, pg_dump/pg_restore |
| Django | Settings, migrations, manage.py check --deploy, how it reads environment variables |
| AWS core | Regions, VPC, subnets, security groups, EC2, RDS, IAM roles vs users |
| TLS | What a certificate is, Let's Encrypt/certbot basics |
If any row feels shaky, learn it first. Chapter 3 assumes it.
2.2 Accounts and access¶
| Item | Why | Notes |
|---|---|---|
| AWS account with billing set up | Everything | One account per client/organisation, ideally separate accounts (or at least separate VPCs) for production and staging |
| Your own IAM identity with MFA | Daily work | Never work as the root user |
| Permissions for each chapter | Avoid getting stuck halfway (as with security groups during the incident) | See 2.3 |
| Domain + DNS access (Route 53 or the registrar) | TLS certificates, pointing the domain at the server | You must be able to create/change A records |
| Fixed office IP (or a small known list) | SSH allow-list | If the office IP changes often, plan for Session Manager (Ch. 6) instead of SSH |
| Alert email address (a shared mailbox is better than a person) | GuardDuty, alarms, budgets | Someone must actually read it |
| Source repository access | Deployment | Read-only deploy key or token for the server |
| Third-party credentials the app needs (email/SES, push notifications, app-store keys, payment) | App configuration | Separate keys per environment |
2.3 AWS permissions checklist¶
Ask for these before the work starts. Missing permissions mid-incident cost time.
| Task | Permissions (service: actions) |
|---|---|
| Security groups | EC2: CreateSecurityGroup, AuthorizeSecurityGroupIngress/Egress, RevokeSecurityGroupIngress/Egress, DeleteSecurityGroup, ModifyInstanceAttribute (change an instance's groups), CreateTags |
| EC2 | EC2: RunInstances, DescribeInstances, AllocateAddress, AssociateAddress, key pair actions; IAM: PassRole for the instance role |
| RDS | RDS: CreateDBInstance, ModifyDBInstance, CreateDBSubnetGroup, CreateDBParameterGroup, ModifyDBParameterGroup, DescribeDBLogFiles, DownloadDBLogFilePortion, snapshot actions |
| Secrets | Secrets Manager: GetSecretValue, RotateSecret, DescribeSecret |
| Logging & detection | CloudTrail (trails, LookupEvents), CloudWatch (alarms, logs), GuardDuty, SNS, EventBridge |
| Session Manager | SSM: StartSession; IAM: create a role with AmazonSSMManagedInstanceCore |
Read-only access is enough for an audit (Chapter 13). Write access is needed to fix anything.
2.4 Tools on your laptop¶
| Tool | Used for | Check |
|---|---|---|
| AWS CLI v2 | Scripted checks, log downloads | aws --version (or use CloudShell in the console: no install, uses your console login) |
| OpenSSH client | Server access | ssh -V |
| git | Code | git --version |
| Docker + Compose plugin | Testing compose files locally before deploying | docker compose version |
psql (PostgreSQL client) |
DB checks | psql --version (or docker run --rm -it postgres:16-alpine psql …) |
dig, nc (netcat) |
DNS and port checks from outside | dig -v, nc -h |
openssl |
Generating secrets, checking TLS | openssl version |
curl |
HTTP checks, finding your public IP | curl -s https://checkip.amazonaws.com |
| A password manager | Storing generated secrets | Never a text file on the desktop |
| A second network (phone hotspot) | Testing exposure from outside the office | The office IP may be allow-listed, which hides problems |
2.5 Decisions to make (write the answers down)¶
| Decision | Options | Recommendation |
|---|---|---|
| Region | Closest to users / data-residency rules | Pick one, use it consistently |
| Environments | prod, staging, (dev) | Separate everything per environment (R9) |
| Database | RDS vs self-hosted in Docker | RDS for production. Self-hosted only for staging/dev, and only with the hardening in Chapter 8.2 ("Self-hosted Postgres") |
| Cache/broker | Redis in Docker vs ElastiCache | Docker on an internal network is fine for small setups |
| Server access | SSH from office IP vs Session Manager | Session Manager if possible; otherwise SSH from a fixed IP |
| How the app gets secrets | .env file vs Secrets Manager at runtime |
.env (chmod 600) to start, Secrets Manager later |
| Naming | <project>-<env>-<role> |
Decide <project> now; you can't rename security groups later |
| Who gets alerts | Mailbox / chat channel | Must be monitored |
| Backup retention | Days to keep | ≥ 7 days for RDS automated backups, plus off-server dumps |
2.6 Information sheet (fill in before starting)¶
Project short name (<project>):
AWS account ID / alias:
Region:
Domain (prod / staging):
Office IP(s):
Alert email:
VPC (new or existing, ID):
Public subnets: Private subnets (for RDS):
Instance type (prod / staging):
DB engine version: Instance class:
Backup retention (days):
Person responsible (Owner tag):
2.7 Cost awareness¶
Things that cost money and are easy to forget: Elastic IPs not attached to a running instance, NAT gateways, RDS Multi-AZ, Performance Insights beyond the free tier, CloudWatch Logs storage without a retention period, GuardDuty (small, worth it). Set an AWS Budget alert on day one (Chapter 4). A sudden bill increase can also be the first sign of abuse.