Introduction
This project focuses on setting up an AWS Load Balancer for a single Amazon EC2 instance. By creating a Load Balancer, you prepare your environment for future scalability (even if you only have one instance right now).
Why is it useful?
Prerequisites
Step-by-Step Implementation
Create and Configure an EC2 Instance
We will create a single EC2 instance that falls under the free tier (e.g., t2.micro or t3.micro, depending on availability in your region).
Manual Steps (Graphical User Interface - GUI)
In the AWS Management Console, go to EC2.
Click Launch Instances.
Name your instance, for example: MyFreeTierInstance.
Choose Amazon Linux 2 AMI (Free Tier eligible).
Select t2.micro (or another free-tier eligible type).
Configure Key Pair: Either select an existing key pair or create a new one (to SSH into the instance later).
Network Settings:
Leave the default VPC selected.
Create or select an existing Security Group. Make sure inbound rules allow at least SSH (port 22) and HTTP (port 80) for testing.
Click Launch Instance.
CLI Equivalent:
Create a key pair (if you don't already have one) :
aws ec2 create-key-pair --key-name MyKeyPair --query "KeyMaterial" --output text > MyKeyPair.pem
chmod 400 MyKeyPair.pem
Create a security group
Add inbound rules (SSH on 22, HTTP on 80)
Launch the instance using the AMI for Amazon Linux 2 (replace 'ami-123abc45' with a valid AMI ID in your region)
Create a Target Group
A Target Group is where your EC2 instance(s) will be registered so the Load Balancer can route traffic to them.
Manual Steps (GUI)
Still in the EC2 dashboard, go to Target Groups under Load Balancing.
Click Create target group.
Choose a target type: select Instances.
Give it a name (e.g., MyTargetGroup).
Protocol: HTTP; Port: 80.
VPC: select the same VPC where your EC2 instance resides.
Click Next and select the newly launched instance to register.
Click Create target group.
CLI Equivalent:
(Replace <YourVPCID> with the VPC ID where your instance is running.)
Register your instance with the target group:
(Replace <YourTargetGroupARN> and <YourInstanceID> with the actual values returned from the previous steps.)
Create an Application Load Balancer
We’ll create an Application Load Balancer (ALB) that forwards HTTP traffic on port 80 to the target group.
Manual Steps (GUI)
Go to Load Balancers under Load Balancing in the EC2 dashboard.
Click Create Load Balancer.
Select Application Load Balancer.
Name your ALB, e.g. MyLoadBalancer.
Scheme: Internet-facing (so it’s publicly accessible).
IP address type: IPv4.
Network Mapping: Select the same VPC as your EC2 instance. Choose at least two Availability Zones for higher availability.
Listeners: By default, an HTTP listener on port 80 is created.
Security Groups: Select or create one that allows inbound HTTP traffic.
Default Action: Choose Forward to MyTargetGroup.
Click Create Load Balancer.
CLI Equivalent:
Create the load balancer
Create a listener that forwards traffic to the target group
(Replace <SubnetID1>, <SubnetID2>, <YourLoadBalancerARN>, <YourSecurityGroupID>, and <YourTargetGroupARN> with your values.)
Common Issues and Troubleshooting
Conclusion
We have successfully created a Load Balancer in AWS and attached a single EC2 instance to it, all while staying within free-tier eligibility. We configured security groups, set up a target group, and routed traffic through an Application Load Balancer. We also learned how to verify our setup via both the AWS Console and the AWS CLI. Through this project, we have gained insights into AWS networking, security, and load balancing fundamentals—preparing us to scale the application further in the future.
Popular Projects
What is Cloud Computing ?
Cloud computing delivers computing resources (servers, storage, databases, networking, and software) over the internet, allowing businesses to scale and pay only for what they use, eliminating the need for physical infrastructure.