Demo: Making Sure Your Web Server Never Takes a Sick Day with AMI, ELB, and Auto Scaling

Demo: Making Sure Your Web Server Never Takes a Sick Day with AMI, ELB, and Auto Scaling

Hi everyone,

In this article, I’ll be walking you through a demo that demonstrates the use of High Availability (HA) and Fault Tolerance (FT) tools—specifically, AMI, ELB, and Auto Scaling—on AWS Cloud.

This hands-on guide will teach you how to leverage three powerful AWS tools to ensure your web server (or any workload) stays up and running—no sick days allowed! 😄


Prerequisites

Before we get started with the demo, make sure you have the following:

  1. An active AWS account: You’ll need access to the AWS Management Console to follow along with the steps.
  2. Basic understanding of AWS services: Familiarity with EC2, ELB, and Auto Scaling will be helpful but not required.
  3. A web browser: We’ll be navigating the AWS console, so make sure you’ve got that ready.
  4. A little patience: We’re going to be setting up several services, so just a little patience while things are being created. It’s all worth it.

So sit tight, but don’t sit too tight—because you’ll be joining in on the performance by doing this at your end as well. Let's dive in.


Step 1: Launching the Web Server Instance (EC2)

To kick things off, I launched an EC2 instance using the Amazon Linux AMI. I used a simple user data script to automatically install and configure an Apache web server. It’s quick, easy, and sets the stage for everything else we’re about to do.

  1. Log in to your AWS Console and navigate to the EC2 Dashboard. You can either find EC2 in the services menu or search for it using the search bar at the top.

Article content

2. On the EC2 Dashboard, click the Launch Instance button. This is where we’ll begin configuring our new instance.

Article content

3. Now, let’s configure the instance.

  • Name: Give it a name; mine is "web-server"
  • AMI: Choose your desired AMI; I’m using Amazon Linux 2. It’s a lightweight and easy-to-use OS for running a web server.
  • Instance type: Select your instance type. For a basic setup, the t3.micro instance type should be sufficient (this is eligible for the AWS Free Tier if you're just experimenting).

Article content

  • For key pair login, click on 'Create Key Pair' or choose an existing key pair of your choice.
  • Using a key pair is optional, but since I may need to connect to my instance for troubleshooting or recovery in case of failure, I’ll be creating one.

Article content

4. Set up any additional details like network settings. For simplicity, you can leave the defaults, but make sure to assign the instance to your desired VPC and subnet.

  • Under Network Configurations, I'll create a firewall using a security group and attach two rules: one for SSH (to enable secure login via the shell) and another for HTTP (so we can access our webpage).
  • Next, I’ll configure the storage. For the root volume, I'll go with 30 GB using the gp3 type.
  • Expand the advanced details section.

Article content

5. Under Advanced Details, scroll down to the 'User Data' box and paste the following script:

#!/bin/bash

yum update -y

yum install -y httpd

systemctl start httpd

systemctl enable httpd

echo "<html><h1>Welcome to My High Availability Project!</h1></html>" > /var/www/html/index.html

Article content

What the script does:

  1. #!/bin/bash

This line tells the instance to use the Bash shell to execute the script.

2. yum update -y

This updates all packages on the instance to ensure it has the latest security patches and updates.

3. yum install -y httpd

Installs the Apache HTTP server (httpd) on the instance to serve the web pages.

4. systemctl start httpd

Starts the Apache HTTP server, enabling it to begin serving web pages.

5. systemctl enable httpd

Configures the Apache server to start automatically on system boot.

6. echo "Hello, World! Welcome to my Web Server!" > /var/www/html/index.html

Creates a simple HTML file with a message and places it in the default directory for Apache to serve.

  • On the right-hand side, Review and Click on Launch instance



Step 2: Create an AMI from the Web Server

  1. Navigate to the Instances page to view the newly created instance.

  • Refresh the page and ensure the status checks are passed and the instance transitions from Initializing to checks passed.
  • Tick the box next to your instance, and under the Details section below, copy the IPv4 Public IP.

Article content

  • Open a new tab in your browser and paste the copied IP address to confirm your web server and the simple web page are up and running.
  • Once verified, go back to the Instances page.

Article content

2. Click on the Actions menu, navigate to Images and Templates, and select Create Image.

Article content

3. Give your image a name (mine is HA-project-image), optionally add a description, and then click Create image.

Article content

Step 3: Launching an Instance from the AMI to Test High Availability and Fault Tolerance.

  1. Navigate to the AMIs section Under the "Images" category on the left-hand menu.

  • Locate the AMI you just created, tick the checkbox next to it, and click on Launch instance from AMI.
  • Ensure the filter is set to Owned by me to display the AMI you’ve created.

Article content

2. Configure the instance:

  • Name: Give your new instance a name
  • AMI: The AMI section will default to the image you just created. No changes needed here.

Article content

  • Key pair: Use a key pair of your choice, ideally the same one created earlier for secure access.
  • SG: Select the security group created for your first instance. This ensures HTTP and SSH access are configured.
  • Click Launch instance.

Article content


3. Navigate back to the Instances page to check the newly created instance.

  • Refresh the page a few times until the status check shows 3/3 checks passed.
  • Tick the checkbox next to the newly created instance, and copy the IPv4 Public IP address from the details section below.

Article content

  • Open a new browser tab, paste the IP address, and hit Enter.
  • This step will allow you to verify that the web server is running with the same configurations and content as the previous instance, demonstrating that the AMI successfully preserved the state of the original instance.

Article content

Step 4: Creating a Launch Template with Your AMI

A Launch Template simplifies launching instances by pre-defining the settings you’ll reuse.

  1. Navigate to the Launch Templates Section on the EC2 Dashboard, locate and click on Launch Templates under New launch template.

Article content

2. Configure the launch template:

  • Template Name and Description: Give your template a name (mine is HA-FT-launchTemplate) and optionally provide a description, like "launch template for HA and FT demo"
  • Next, tick the checkbox for Auto Scaling guidance. This ensures the template is optimized for use with Auto Scaling.
  • Under Application and OS Image (AMI), double-check that your custom AMI is selected. If it isn’t, select My AMIs, and choose the AMI you created earlier.

Article content

  • Instance Type: Choose an instance type that matches your needs. For this demo, I’ll stick with t3.micro, which is free tier eligible.
  • Key Pair: Use an existing key pair or create a new one if required. This will help in troubleshooting or SSH access if needed.
  • Security Group: Attach the same Security Group created during the initial instance setup. This ensures you retain the necessary rules for HTTP and SSH access.
  • Click Create launch template

Article content

Step 5: Setting Up an Auto Scaling Group

  1. Navigating to the Auto Scaling Groups section under the EC2 dashboard. Click Create Auto Scaling Group.

Article content

2. Give your Auto Scaling Group a name; mine is "HA&FT-ASG".

  • Under the launch template section, select the newly created launch template from the previous step.
  • Double-check to ensure the correct version of the template is selected. Once done, click Next to proceed.


Article content

3. In the VPC and Subnets section, choose the VPC where your instances will run.

  • For high availability, select multiple Availability Zones (AZs) by ticking the checkboxes for subnets in different AZs. This ensures that your instances are distributed across multiple AZs for fault tolerance.
  • After configuring the VPC and AZs, click Next to proceed.

Article content

4. In the Load Balancing section,

  • Choose Attach to a new load balancer.
  • Select Application Load Balancer (ALB) as the load balancer type.
  • Set the Scheme to Internet-facing to ensure that your ALB can handle external web traffic. This configuration enables the ALB to distribute incoming requests to instances in your Auto Scaling Group.

Article content

  • In the Target Group section, select Create a target group.
  • A target group is created automatically. The name is generated based on your load balancer and Auto Scaling Group configuration.
  • This target group will be used to route traffic to the instances in your Auto Scaling Group.

Article content

5. In the Group Size and Scaling section, configure the size and scaling parameters for your Auto Scaling Group:

  • Desired Capacity: Set to 2. This is the number of instances that should be running at all times under normal circumstances.
  • Minimum Capacity: Set to 1. This is the minimum number of instances that will remain running, even during scaling events.
  • Maximum Capacity: Set to 3. This is the upper limit of instances the Auto Scaling Group can scale up to during increased demand.
  • For the other settings and steps, keep the defaults for simplicity in this demo. Once everything is configured, click on Create Auto Scaling Group.

Article content

Step 6: Test Auto Recovery

  • Navigate back to the Instances page to view the instances created by the Auto Scaling Group. You should see the instances that are automatically launched as part of the Auto Scaling configuration.

Article content

Next Step: Challenge

Now that you’ve seen the instances created by the Auto Scaling Group in the screenshots, here’s your challenge:

  • Go ahead and terminate one of the instances from the Auto Scaling Group.
  • After a short while, refresh the page and see if the Auto Scaling Group steps in to automatically launch a new instance to maintain the desired capacity.
  • Give it a try and see how well Auto Scaling handles the recovery. Let me know your observations in the comments below.


Camille D.

AWS DevOps | Python | Kubernetes | Docker | CICD | Ansible | Prometheus | Grafana | Terreform | Blockchain

4mo

This is great Edwina

Kris Fernando

Innovative Solutions Architect & Cloud Consultant | Transforming Enterprises with Cutting-edge Cloud Strategies | AWS Community Builder & Certified Solutions Architect

4mo

Love this 🙌🏽 great work Edwina Abah

Queen Theresa Abah

Author of fictions and poetry & wordsmith for beauty and luxury brands | Eliciting the Human Experience with elegance and flair.

4mo

Useful tips

To view or add a comment, sign in

More articles by Edwina Abah

Insights from the community

Explore topics