# Running scalable httpd service on AWS

## Prerequisites

1. An AWS Account
    
2. Basic knowledge regarding **EFS, ASG, LaunchConfig, ALB, and EC2**.
    
3. We’ll be using `**t2.micro**` instance type as it is under AWS Free Tier, but I will still use Spot Instance :D.
    
4. We’ll be deploying our instances in `**Public Subnet**`, using the default VPC inside of AWS that was created for you by default.
    
5. Basic VPC Knowledge; **CIDR, Subnet, Route Tables, etc**
    

---

## #1: Creating your custom EC2 Security Group

> **SG #1**
> 
> **Name:** efs-sg-default  
> **Description:** Allows EFS Access  
> **VPC:** AWS Default VPC  
> **Inbound rules**  
> 1\. NFS -&gt; 0.0.0.0/0  
> **Tags**  
> Name -&gt; Allow EFS  
> **Others**  
> Set it as default

> **SG #2**
> 
> **Name:** alb-sg  
> **Description:** Allows HTTP Access via ALB (Port 80)  
> **VPC:** AWS Default VPC  
> **Inbound rules:**  
> 1\. HTTP -&gt; 0.0.0.0/0  
> **Tags:**  
> Name -&gt; Allow HTTP for ALB  
> **Others**  
> Set it as default

> **SG #3**
> 
> **Name:** ec2-sg  
> **Description:** SG for EC2  
> **VPC:** AWS Default VPC  
> **Inbound rules**  
> 1\. HTTP -&gt; alb-sg (Select SG)  
> 2\. SSH -&gt; 0.0.0.0/0  
> **Tags**  
> Name -&gt; SG for EC2  
> **Others**  
> Set it as default

## #2: Creating your EFS (Elastic File System)

### **Configurations:**

> **Name:** Website Data  
> **Availability and durability:** One Zone  
> **AZ:** ap-southeast-1  
> **Automatic backups:** Disabled  
> **Lifecycle management:** None  
> **Performance mode:** General Purpose  
> **Throughput mode:** Bursting  
> **Encryption (Data at rest):** Turned on  
> **VPC:** default  
> **Subnet:** Default Subnet (Depending on the AZ selected)  
> **Security Group:** Created from #1 (efs-sg-default)
> 
> **\* Leave everything else as default and create your EFS**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767059341680/96f14924-ac31-470f-b9ab-aee84efb1354.png align="left")

## #3: Creating Launch Template

> **Name:** httpd-template  
> **Auto Scaling guidance:** Optional but I have turned it on  
> **AMI:** Amazon Linux 2  
> **Instance type:** t2.micro (Free tier eligible)  
> **Key pair:** Select any existing Key pair, or create a new one.  
> **Security Group:** Select **“efs-sg-default” & “ec2-sg”** SG created from #1  
> **Storage:** Default (8 GB)
> 
> **Advanced Details**  
> **Request Spot Instances:** Enabled  
> **IAM instance profile:** Select any IAM Role if you have
> 
> **User Data Script:**  
> #!/bin/bash  
> sudo yum update -y  
> sudo yum install httpd -y  
> sudo systemctl start httpd  
> sudo systemctl enable httpd  
> sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport **“your\_efs\_ip”**:/ /var/www/html

**<mark>NOTE</mark>**<mark>:<br>**You may need to replace </mark> **<mark>“your_efs_ip”</mark>** <mark> with the real ID of your EFS which you may find in the AWS Management Console.</mark>

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767059343140/13ca3b11-e259-42d7-b457-bfd1880c1334.png align="left")

## #5: Creating Target Groups for ALB

> **Choose a target type:** Instances  
> **Target group name:** httpd-tg  
> **Protocol:** HTTP -&gt; Port 80  
> **VPC:** AWS Default VPC  
> **Health check protocol:** HTTP  
> **Health check path:** /
> 
> Click on **“Next”**
> 
> **Register Instances:** Do not select any instances
> 
> *Finally, create the Target Group*

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767059344323/cec13f83-a773-42c0-b729-8895787aa5a3.png align="left")

## #6: Create Application Load Balancer

> **Name:** httpd-alb  
> **Scheme:** Internet-facing  
> **IP address type:** IPv4  
> **VPC:** AWS Default VPC  
> **Subnet Mappings:** Select all  
> **Security Group:** Created from #1 (allow-http-for-alb)  
> **Target Group:** Created from #5 (HTTP: 80 -&gt; httpd-tg)
> 
> **<mark>And create it!</mark>**

## #7: Create Auto Scaling Group

> **Auto Scaling group name:** httpd-asg  
> **Launch template:** Created from #4) (httpd-template)  
> **VPC:** AWS Default VPC  
> **AZ:** Select all  
> **Attach existing Load Balancer:** Created from #6 (httpd-alb)  
> **Desired capacity:** 2  
> **Minimum capacity:** 1  
> **Maximum capacity:** 2  
> **Scaling policies:** None for now  
> **Instance scale-in protection:** Disabled  
> **Tags:**  
> 1\. **Name -&gt; “HTTPD Instance”**
> 
> **And create it!**

Upon a success creation of resources in the steps above, you can now visit the URL of your ALB on the browser and enjoy it ! Your website files are now gathered in all the EC2 instances via EFS, and load balanced.

To add a new file, or change something — All you have is to SSH into one of the instances and change the files. It will be automatically reflected across all the other instances.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1767059345529/d0f6752e-8941-477d-bb3a-694940b19c5c.png align="left")
