Integrate EC2 Instance with ALB

Amazon’s Application Load Balancer (ALB) is a vital component of an elastic and scalable architecture, facilitating seamless distribution of HTTP/HTTPS traffic across EC2 instances. This guide outlines the step-by-step procedure to integrate an EC2 instance with an ALB, ensuring optimal performance and fault tolerance.



1. Prerequisites

An EC2 instance is already launched and running with a web application deployed.

Security groups are configured to allow HTTP/HTTPS traffic.

A VPC with at least two subnets for high availability.

IAM permissions to create and manage EC2, ALB, and target groups.





2. Create a Target Group

1. Navigate to the Target Groups Section:

Open the EC2 Dashboard in the AWS Management Console.

Under the Load Balancing section, select Target Groups.



2. Create a New Target Group:

Click Create Target Group and specify the following:

Target type: Instances.

Protocol: HTTP or HTTPS.

VPC: Select the VPC where the EC2 instance resides.




3. Health Check Configuration:

Define a health check path (e.g., /healthcheck).

Set thresholds for health check success and failure (e.g., 3 healthy responses).



4. Register Targets:

Select your EC2 instance from the list and add it to the target group.

Click Include as Pending and then Register Targets.






3. Create an Application Load Balancer

1. Navigate to the Load Balancers Section:

In the EC2 Dashboard, click Load Balancers and choose Create Load Balancer.



2. Select ALB Type:

Choose Application Load Balancer for HTTP/HTTPS traffic.



3. Configure Basic Settings:

Name the ALB (e.g., MyAppALB).

Select Internet-facing or Internal based on your use case.



4. Configure Listeners:

Add a listener for HTTP (Port 80) or HTTPS (Port 443).

For HTTPS, upload an SSL certificate in the ACM Console.



5. Select Availability Zones:

Choose subnets from at least two availability zones to ensure high availability.





4. Associate Target Group with ALB

1. Add Target Group to Listener:

During ALB creation, associate the previously created target group with the listener.



2. Review and Create:

Review the configuration and click Create Load Balancer.




5. Configure Security Groups

1. ALB Security Group:

Configure the ALB security group to allow inbound HTTP/HTTPS traffic.



2. EC2 Security Group:

Ensure the EC2 security group allows inbound traffic from the ALB.




6. Test the Setup

1. Access the ALB DNS:

Obtain the ALB DNS name from the Load Balancer details page.

Open the DNS URL in a browser to confirm traffic routing to the EC2 instance.



2. Check Health Checks:

Verify that the EC2 instance passes the health checks.




Conclusion

By integrating an EC2 instance with an Application Load Balancer, you achieve a fault-tolerant, scalable, and secure architecture. ALB’s advanced routing capabilities ensure optimized traffic distribution while simplifying the management of workloads hosted on EC2 instances.

The article above is rendered by integrating outputs of 1 HUMAN AGENT & 3 AI AGENTS, an amalgamation of HGI and AI to serve technology education globally.

(Article By : Himanshu N)