Amazon Web Services (AWS) provides a scalable and highly available platform to host web applications. One of the services provided by AWS is the Application Load Balancer (ALB) that can distribute incoming traffic across multiple targets, such as EC2 instances, containers, and IP addresses. In this tutorial, we will cover how to set up an ALB, an EC2 instance, and how to secure the connection to the web server with SSL.
Step 1: Create an EC2 instance
- Open the AWS Management Console.
- Go to the EC2 dashboard.
- Click on the "Launch Instance" button.
- Choose the Amazon Linux AMI and select the instance type.
- Configure the instance settings as desired, then proceed to the next step.
- Add storage to the instance as needed and configure the security group to allow incoming HTTP traffic on port 80.
- Launch the instance.
Step 2: Install a web server on the EC2 instance
- Connect to the EC2 instance using SSH.
- Install the Apache web server by running the following command:
sudo yum install httpd -y
- Start the Apache service by running the following command:
sudo systemctl start httpd
- Verify that the Apache service is running by visiting the public IP address of the EC2 instance in a web browser.
Step 3: Create an Application Load Balancer
- Go to the EC2 dashboard.
- Click on the "Load Balancers" menu option.
- Click on the "Create Load Balancer" button.
- Select the "Application Load Balancer" option and click on the "Create" button.
- Give the load balancer a name, select the appropriate VPC, and configure the listeners as desired.
- Choose the availability zones to host the ALB, then proceed to the next step.
- Add the EC2 instance as a target, then click on the "Create" button.
Step 4: Secure the connection with SSL
- Obtain an SSL certificate for your domain, either by purchasing one from a certificate authority or by using AWS Certificate Manager to generate a free certificate.
- Upload the SSL certificate to the ALB.
- In the EC2 dashboard, go to the Load Balancer section, click on the ALB you created and navigate to the "Listeners" tab.
- Click on the HTTPS listener and select the SSL certificate.
- Save the changes.
Step 5: Verify the setup
- Visit the DNS name or public IP address of the ALB in a web browser, using the HTTPS protocol.
- Verify that the SSL certificate is valid and that the connection is secure.
- Verify that the ALB is routing traffic to the EC2 instance and that the web server is accessible.
With these steps, you should have a fully functional Application Load Balancer with an EC2 instance and SSL enabled. You can now customize and configure the web server and the ALB as desired to fit your requirements.