Skip to content
vfernandezg.devProjectsContact
All projects

AWS infrastructure as code

A reservations platform on AWS defined in Terraform. CloudFront and a WAF in front of ECS Fargate and RDS PostgreSQL in private subnets, with tests, security scanning and approval-gated deploys.

AWS architecture diagram. Users enter through CloudFront with a WAF, towards S3 or towards API Gateway with Cognito; a VPC Link leads to the internal load balancer, ECS Fargate and RDS PostgreSQL in private subnets. Below, the delivery flow from pull request to plan, approval, apply and smoke testAWS architecture diagram. Users enter through CloudFront with a WAF, towards S3 or towards API Gateway with Cognito; a VPC Link leads to the internal load balancer, ECS Fargate and RDS PostgreSQL in private subnets. Below, the delivery flow from pull request to plan, approval, apply and smoke test
Role
University team project with five students in 2025; complete redesign and sole author of the current version in 2026
Period
Jun 2025 — Jul 2025
Status
Completed
Stack
  • Terraform
  • AWS
  • GitHub Actions
  • Docker
  • PostgreSQL
  • Checkov
  • Jenkins

The project started in 2025 as a university team project: a first Terraform deployment of a reservations system, with EC2 instances, a public load balancer, RDS MySQL and Jenkins pipelines. In November 2026 I redesigned it from scratch on my own. The current version defines in Terraform the platform of an event reservations business, with three environments (development, staging and production) that come from a single root module and thirteen modules.

Architecture

  • Edge. CloudFront with a WAF is the only public entry point. The static site is served from a private S3 bucket, and /api/* routes go to an API Gateway HTTP API that validates the JWT issued by Cognito.
  • Private core. API Gateway reaches an internal load balancer through a VPC Link, and from there ECS Fargate tasks on ARM64 with auto scaling. Nothing inside the VPC is exposed to the internet.
  • Data. RDS for PostgreSQL 18 lives in isolated subnets with no outbound route. In production it keeps a standby replica in another zone (Multi-AZ).
  • Network. A three-tier VPC across two availability zones. Security groups are chained by reference, from the VPC Link to the load balancer, the tasks and the database; no inbound rule uses an IP range.

Engineering decisions

  • The load balancer is internal and still checks a header. API Gateway always exposes its own public address, and calling it directly would skip the WAF. CloudFront adds a secret header and the load balancer answers 403 without it.
  • No password in the code or in the state. RDS generates and rotates the database password in Secrets Manager, and ECS injects it when the task starts. CI reaches AWS through GitHub OIDC roles, with no long-lived keys.
  • From Aurora to RDS. The first real deployment ran in an AWS Free plan account, which cannot create Aurora Serverless inside a VPC. Rather than move the database out of the private network, I switched to RDS for PostgreSQL and recorded the decision in an ADR.
  • Cost by environment. Graviton for the tasks and the database, Fargate Spot and a single NAT outside production, and Multi-AZ in production only. What changes between environments lives in one variables file per environment.

Quality and delivery

  • Tests. 25 terraform test cases with a mocked AWS provider: subnet layout, security group chaining, JWT routes, encryption and database high availability.
  • Scanning. TFLint, Trivy and Checkov, with about 280 policies on the production settings and no failures, against the 62 checks that failed in the original project. Every exception is justified next to its resource, and gitleaks scans the full history for secrets.
  • Deploys. Every pull request gets the Terraform plan as a comment. Apply is manual: plan, approval by the environment reviewers, apply of that same saved plan, and smoke tests against the deployed environment.
  • Image. The ARM64 application image is pushed to ECR with its software bill of materials (SBOM) and a signed provenance attestation.
  • Jenkins. The repository keeps an alternative pipeline with the same checks and a controller configured as code.

CI run on GitHub Actions with six passing checks: Terraform format, validation and tests, TFLint, Trivy and Checkov, terraform-docs, gitleaks, and Dockerfile and script linting CI run on GitHub Actions with six passing checks: Terraform format, validation and tests, TFLint, Trivy and Checkov, terraform-docs, gitleaks, and Dockerfile and script linting

The deployed environment

The development environment was deployed to AWS with this same configuration and the version of the latest commit: 115 resources managed by Terraform. It is not kept running, because the NAT, the load balancer and the database are billed by the hour, so what follows is the record of that deployment, from 14 November 2026.

The smoke test of the repository, end to end:

PASS  Static site served from S3 via CloudFront                200
PASS  API health through CloudFront                            200
PASS  Anonymous API route                                      200
PASS  Database round-trip over TLS                             200
PASS  Protected route without a token is rejected              401
PASS  WAF blocks a SQL injection probe                         403
PASS  Calling API Gateway directly (bypassing CloudFront)      403
All checks passed.

The ECS service, with its task running, the deployment completed and the load balancer target healthy:

ECS console with the service active, one task running out of one desired, the deployment completed and one healthy load balancer target ECS console with the service active, one task running out of one desired, the deployment completed and one healthy load balancer target

That Fargate task is what answers on the public route, with the deployed version and its availability zone:

Page of the deployed development environment. After pressing the button for the public route, the API answers 200 with a greeting from ECS Fargate on ARM64, the deployed version and the availability zone Page of the deployed development environment. After pressing the button for the public route, the API answers 200 with a greeting from ECS Fargate on ARM64, the deployed version and the availability zone

The database, a PostgreSQL instance on Graviton, and the check that makes a round trip to it:

RDS console with the instance available, PostgreSQL engine and class db.t4g.micro RDS console with the instance available, PostgreSQL engine and class db.t4g.micro

200 response from the database check route, with status ok, engine postgresql and the latency of the query 200 response from the database check route, with status ok, engine postgresql and the latency of the query

The network: six subnets across two availability zones, each tier with its route table and its ways out.

VPC resource map with six public, application and data subnets in two zones, five route tables and three network connections VPC resource map with six public, application and data subnets in two zones, five route tables and three network connections

At the edge, the WAF counted the requests of the tests and blocked the ones carrying a SQL injection; the protected route, without a token, answers 401.

WAF totals over three hours: 87 requests, 81 allowed and 6 blocked WAF totals over three hours: 87 requests, 81 allowed and 6 blocked

401 response from the protected route when called without a token, with the message Unauthorized 401 response from the protected route when called without a token, with the message Unauthorized

And the CloudWatch dashboard that Terraform itself creates, with one chart per tier: CloudFront, WAF, API Gateway, load balancer, ECS and RDS.

CloudWatch dashboard with six charts: CloudFront requests and errors, requests allowed and blocked by the WAF, API Gateway, load balancer timings, ECS CPU and memory, and RDS CPU and connections CloudWatch dashboard with six charts: CloudFront requests and errors, requests allowed and blocked by the WAF, API Gateway, load balancer timings, ECS CPU and memory, and RDS CPU and connections

Limits

The API running on Fargate is a placeholder written in TypeScript, with the database schema of the original project ported from MySQL to PostgreSQL. There is no custom domain yet, the application uses the master secret managed by RDS instead of a least-privilege user, and recovery from a regional outage is on the roadmap.