After the serverless blog (subchapter 33.1), we take a step up in complexity with the second project: a REST API with containers. While the blog was 100% serverless, this project takes you into the world of containers (Chapter 17) and relational databases (Chapter 8), combining ECS Fargate, RDS, and a load balancer (ALB). This is a very common pattern in the real world for backend applications, and it consolidates a different (and highly sought-after) part of your knowledge.

What is a REST API (a quick review)

A REST API is a "gateway" that other applications (a website, a mobile app...) use to make requests to obtain or modify data. For example, an API for a store that the mobile app uses to query products, create orders, etc. It is the backend "brain" that serves data and logic to clients.

   Mobile/web app  ──request──►  REST API  ──►  processes and responds with data
   "give me the products"         (the backend)    [list of products]

This project builds that API, but using containers to run it and a relational database for the data.

The pieces and how they fit together

The project combines three main services, each with its role:

ECS Fargate: run the API in containers (serverless)

Remember containers (Chapter 17): they package your application with everything it needs to run the same way anywhere. ECS with Fargate (subchapter 17.3) runs those containers without you having to manage the underlying servers (Fargate is the serverless option for containers). Here, your API goes inside a container that ECS Fargate runs and scales.

ECS Fargate → runs your API (in a container), without managing servers
   → scales automatically according to demand

💡 This project lets you practice the container workflow we saw: package the app in a Docker image (subchapter 17.1), store it in ECR (subchapter 17.2), and run it in ECS Fargate (subchapter 17.3).

RDS: the relational database

RDS (Chapter 8) provides the relational database (managed by AWS) where the API stores and queries data (products, orders, users...). Unlike the blog (which used DynamoDB, NoSQL), here we use a relational (SQL) database, suitable when data has structured relationships. RDS manages it for you (backups, patches...).

RDS → the relational database where the API stores/queries data

ALB: the load balancer (distributes traffic)

The Application Load Balancer (ALB) (subchapter 13.1) distributes requests among your API containers. If you have several containers running the API (to handle more load), the ALB distributes the traffic among them evenly, and checks their health (remember health checks, subchapter 13.2). It is the "gateway" that receives clients and directs them.

Clients → ALB (distributes traffic) → API containers (multiple)

The complete architecture

This is how the pieces fit together:

   Clients (app, web)
        │
        ▼
   ALB (load balancer: distributes and checks health)
        │
        ▼
   ECS Fargate (multiple containers with your API, auto-scaling)
        │
        ▼
   RDS (relational database: the data)

Clients reach the ALB, which distributes their requests among the API containers (in ECS Fargate), and these read/write to the RDS database. If more traffic arrives, ECS Fargate adds more containers and the ALB includes them in the distribution: it scales automatically.

Key concepts you consolidate

This project strengthens an important (and very employable) part of the book, different from the serverless blog:

   Book concepts you consolidate:
   - Containers: Docker, ECR, ECS Fargate (Ch. 17)
   - Relational databases with RDS (Ch. 8)
   - Load balancing with ALB (Ch. 13)
   - Networking: put the DB in private subnets, protect the API... (Ch. 6)
   - Security: Security Groups, DB secrets (Chs. 6, 23)
   - All with Terraform! (Parts II-V)

⚠️ Best practices to apply (that you have learned in the book):

  • Put the database in private subnets (Chapter 6), not accessible directly from the internet: only the API should be able to talk to it.
  • Store the database password in Secrets Manager (subchapter 23.6), never in the code or in .tfvars (remember subchapter 19.4).
  • Use Security Groups (Chapter 6) so that only the ALB talks to the containers, and only the containers to the database.

Real-world example: someone wants to consolidate their knowledge of containers and relational databases (different from the serverless blog). They build a REST API for a store: package the application in a Docker image, store it in ECR, run it in ECS Fargate (multiple containers), put an ALB in front to distribute traffic, and use RDS for the data (products, orders), with the database in private subnets and the password in Secrets Manager. Everything is deployed with Terraform. By building it, they face real challenges —how to securely connect containers to the database, how to configure the ALB and health checks— and by solving them, they internalize how a real container architecture works. They end up with a real, scalable, and secure API, and a solid grasp of a highly sought-after pattern in the market.

What you should remember

  • The REST API with containers project is a step up from the serverless blog, taking you into the world of containers (Ch. 17) and relational databases (Ch. 8). A REST API is the backend "gateway" that other apps make requests to.
  • It combines three pieces: ECS Fargate (runs the API in containers without managing servers, auto-scales, Ch. 17), RDS (the relational database, Ch. 8), and ALB (distributes traffic among containers, Ch. 13).
  • Architecture: clients → ALB (distributes) → containers in ECS Fargate → RDS (data). It scales automatically by adding containers.
  • Consolidates: containers (Docker/ECR/ECS, Ch. 17), RDS (Ch. 8), load balancing (Ch. 13), networking and security (Chs. 6, 23), all with Terraform.
  • ⚠️ Apply best practices: database in private subnets, password in Secrets Manager (never in code), and restrictive Security Groups.

In the next subchapter, we will tackle a project from the data world: a data platform with Glue, Athena, and Redshift.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved