EC2 SeriesProject 3

Flask on EC2 with ALB, ASG, EBS — Terraform

Automate the Project 2 stack with Terraform and add persistent EBS storage plus HTTPS.

Difficulty

Intermediate

Duration

1-2 hours

Cost

~$1 (more if left running)

Project Overview

This project automates the Flask app deployed in Project 2 by using Terraform to provision the VPC, ALB, Auto Scaling Group, and EC2 instances. It also adds a gp3 EBS volume to each instance for persistent storage and enables HTTPS with ACM.

Learning Objectives

Technical Skills

  • • Provision AWS with Terraform (providers, variables, resources)
  • • Build user-data and a systemd service to run a Flask app
  • • Attach and mount EBS volumes for persistent application data
  • • Automate HTTPS and DNS using ACM and Route 53

AWS Concepts

  • • VPC design with public/private subnets, IGW, and NAT Gateway
  • • Application Load Balancer, Target Groups, and health checks
  • • Auto Scaling Groups with Launch Templates and user data
  • • DNS alias records and ACM certificate validation flows

Technologies Used

Terraform
Infrastructure as Code
Flask
Web Framework
ALB
Load Balancer
Auto Scaling
Scaling Groups
VPC
Networking
EBS
Persistent Storage
Route 53
DNS
ACM
TLS Certificates

Prerequisites

  • • Terraform installed and configured
  • • AWS CLI installed (for verification and manual checks)
  • • EC2 Key Pair created (e.g., MyEC2KeyPair)
    See Appendix for instructions if you need to create
  • • IAM Role for EC2 with SSM permissions (e.g., EC2SSMRole)
    See Appendix for instructions if you need to create
  • • Basic familiarity with EC2, VPCs, and Terraform
  • • A domain you control in Route 53 (e.g., clearedforcloud.com) for creating ec2.clearedforcloud.com — Terraform will request/validate the ACM cert automatically

Architecture Overview

Architecture diagram for EC2 Terraform project

Project Steps

1

Create the Flask App Bootstrap Script (with EBS mount)

+
2

Write the Terraform Configuration (build main.tf in sections)

+
3

Initialize and Apply Terraform

+
4

Test ALB and ASG Behavior

+
5

Simulate Failure and Observe Auto Healing

+
6

Clean Up Resources

+