Skip to content

desgee/Managing-High-Traffic-Applications-with-AWS-Elastic-Load-Balancer-and-Terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Managing High Traffic Applications with AWS Elastic Load Balancer and Terraform

Deploys a highly available web application on AWS using an Application Load Balancer (ALB) and Auto Scaling Group (ASG). Each EC2 instance serves a static HTML page via a lightweight Python HTTP server.

Architecture

Internet
    │
    ▼
[ALB] (port 80)
    │
    ├── EC2 Instance (port 8080)
    ├── EC2 Instance (port 8080)
    └── EC2 Instance (port 8080)  ← scales between 2–10

Resources provisioned:

  • aws_security_group — separate security groups for the ALB and EC2 instances (instances only accept traffic from the ALB)
  • aws_launch_template — latest Amazon Linux 2 AMI, bootstrapped with a user-data script that serves an HTML page
  • aws_autoscaling_group — rolling instance refresh, ELB health checks, spread across all default VPC subnets
  • aws_lb — internet-facing Application Load Balancer
  • aws_lb_target_group — HTTP health checks against /
  • aws_lb_listener — forwards port 80 traffic to the target group

State is stored remotely in S3 (day6-terraform-state-bucket) with DynamoDB locking (terraform-state-locks) in eu-west-2.

Prerequisites

  • Terraform >= 1.0
  • AWS credentials configured (environment variables, ~/.aws/credentials, or IAM role)
  • An S3 bucket named day6-terraform-state-bucket and a DynamoDB table named terraform-state-locks already exist in eu-west-2

Usage

# Initialise (downloads providers and configures the S3 backend)
terraform init

# Preview changes
terraform plan

# Apply
terraform apply

# Destroy all resources
terraform destroy

After a successful apply, the ALB DNS name is printed as an output. Open it in a browser to reach the web cluster.

Variables

Name Description Default
server_port Port the web server listens on 8080
alb_port Port the ALB listener accepts traffic on 80
instance_type EC2 instance type t2.micro
asg_min_size Minimum instances in the ASG 2
desired_size Desired instances in the ASG 5
asg_max_size Maximum instances in the ASG 10

Override any variable at apply time:

terraform apply -var="instance_type=t3.small" -var="desired_size=3"

Outputs

Name Description
alb_dns_name DNS name of the Application Load Balancer

Remote State

Setting Value
Backend S3
Bucket day6-terraform-state-bucket
Key global/s3/terraform.tfstate
Region eu-west-2
Locking DynamoDB — terraform-state-locks
Encryption Enabled

Releases

No releases published

Packages

 
 
 

Contributors

Languages