Tuesday, 16 April 2024

This goal of this lab is to illustrate how to setup a simple EC2 auto scaling service. You will create an auto scaling group with initially only one EC2 instance running. A rule will be setup to automatically launch a second EC2 instance when the CPU usage of the first instance reaches 75%. Here is a mind map of Auto Scaling.

 

Architecture Diagram

lab-006-arch-01

Overview

The EC2 Auto Scaling service enables automatically launching EC2 instances based on pre-defined conditions named scaling policies. A common scenario for auto scaling is launching more instances to cope with a sudden demand increase, for example. Two concepts are key to understand how AWS auto scaling works:

  • Launch Configurations: it allows creating EC2 configurations so the service knows what type of EC2 instance to create when needed; and
  • Auto Scaling Groups: a logical group of EC2 instances controlled by the auto scaling service.

Begin this lab by running steps 1-3 of lab-005, making sure to replace any references to lab-005 with lab-006. Then follow the steps described next.

Step 1 - Create a Launch Configuration

lab-006-scrn-01 lab-006-scrn-02 lab-006-scrn-03 lab-006-scrn-04 Get the user data script here which will install a stress tool and launch an Apache web server. lab-006-scrn-05 lab-006-scrn-06 lab-006-scrn-07 lab-006-scrn-08

Step 2 - Create an Auto Scaling Group

lab-006-scrn-09 lab-006-scrn-10  lab-006-scrn-12lab-006-scrn-11 lab-006-scrn-13 lab-006-scrn-14 lab-006-scrn-15 lab-006-scrn-16

Test and Validation

The EC2 Auto Scaling service must automatically launch one EC2 instance based on the EC2 launch configuration that you created. Connect to this instance through SSH and run the following commands to artificially increase CPU utilization.

stress -c 200

You can then begin monitoring the instance's CPU utilization increase and verify than when it reaches 75% or above a new EC2 instance will automatically be launched by the auto scaling service.

lab-006-scrn-17 lab-006-scrn-18 lab-006-scrn-19 lab-006-scrn-20

The goal of this lab is to illustrate how to use an Application Load Balancer to distribute requests over two web servers running on distinct Availability Zones. Here is a mind map of ELB (Elastic Load Balancing).

 

Architecture Diagram

lab-005-arch-01

Overview

AWS Elastic Load Balancing (ELB) service supports three types of load balancers:

  • Application Load Balancer,
  • Network Load Balancer, and
  • Classic Load Balancer.

As the name suggests, the Application Load Balancer works at the application layer and understands protocols such as HTTP. This gives the load balancer the ability to support routing rules based on the URL or the host field in the HTTP header, for example.

Step 1 - Create VPC and Subnets

Create a new VPC with the Name tag lab-005 and the IPv4 CIDR block 192.168.0.0/16. Then create two public subnets in distinct availability zones of your VPC. Make sure to set the CIDR IPv4 block correctly to each subnet according to the ranges specified in the architecture diagram. You can use tags subnet-A and subnet-B for the subnets.

lab-005-scrn-01 lab-005-scrn-02 lab-005-scrn-03 lab-005-scrn-04 lab-005-scrn-05 lab-005-scrn-06 lab-005-scrn-07

Step 2 - Create an Internet Gateway

Create an Internet gateway with the Name tag lab-005 and attach it to lab-005 VPC. This procedure is described in detail in step 2 of lab-002.

Step 3 - Modify the Main Route Table

Add a default route on your VPC router with a destination to the Internet gateway created in the previous step. Go to Subnet Associations and associate both subnets to the Main Route Table.

lab-005-scrn-08 lab-005-scrn-09 lab-005-scrn-10 lab-005-scrn-11

Step 4 - Launch EC2 Instances

Launch an EC2 instance on each of the public subnets you created in the first step of this lab.

  1. You can use Amazon Linux 2 AMI.
  2. You can choose the Free tier eligible instance type.
  3. Make sure to set the correct VPC and subnet for each instance; also, use the provided user-data to setup an HTTP server on your instances.
  4. You can select the suggested storage for your instances.
  5. You should add a Name tag to help identifying your instances.
  6. Both instances should be in a Security Group with inbound rules that accept SSH and HTTP traffic.
  7. You should secure your instances by creating a lab-005 key pair.

At this point you should be able to access both instances using a browser an the instances public IP addresses. You should be able to see the hostname of each instance as the index page.

Step 5 - Create the Application Load Balancer

Follow the procedure described by the screenshots. lab-005-scrn-12 lab-005-scrn-13 lab-005-scrn-14 lab-005-scrn-15 lab-005-scrn-16 lab-005-scrn-17 lab-005-scrn-18 lab-005-scrn-19 lab-005-scrn-20

Test and Validation

Copy the DNS name associated with the load balancer and, using a browser, try to access it. You should be able to see alternate responses (as you refresh the page) of the two instances webpages which proves that the load balancer is working properly by redirecting the request evenly to the two instances.

lab-005-scrn-21

Another test you should do is to stop one of the instances and verify that the load balancer will not send requests to the stopped instance anymore.

Monday, 15 April 2024

This lab is similar to lab-003 but instead of using a Nat gateway you are asked to use a Nat instance.

 

Architecture Diagram

lab-004-arch-01

Overview

As mentioned before, this lab is very similar to lab-003 except that you will create a Nat instance instead of a Nat gateway. To do just that, when you create the EC2 instance in the public subnet (the one labeled B), make sure to choose an AMI that comes with pre-installed NAT software.

Step 1 - Run Lab-002

Repeat all of the steps described in lab-002, making sure that any references to lab-002 are replaced by lab-004. The security group for the instance in the private subnet (the one labeled B) must have an inbound rule that enables not only SSH but also HTTP traffic. For the EC2 instance in the public subnet (the one labeled A), follow the specific instructions described in the next step.

Step 2 - Launch an EC2 Instance with NAT Software

Search the community AMIs for one with NAT software pre-installed. After the instance is launched, make sure to enable port forwarding by disabling source/destination check.

lab-004-scrn-01 lab-004-scrn-02 lab-004-scrn-03

Step 3 - Create a Route Table

Create a new route table with the Name tag private and with a default route to the NAT instance created in step 2.

Step 4 - Associate the Route Table to the Private Subnet

Associate the newly created route table to the private subnet.

This lab illustrates how an EC2 instance running in a private subnet can be configured to access the internet with the help of a service called Nat gateway.

 

Architecture Diagram

lab-003-arch-01

Overview

In order to achieve the goal of this lab, you will have to go through the following steps:

Step 1 - Run Lab-002

Repeat all of the steps described in lab-002, making sure that any reference to lab-002 are replaced by lab-003.

Step 2 - Create a NAT Gateway

Create a NAT gateway in the public subnet. Note that an elastic public IP must be allocated before a NAT gateway can be created.

lab-003-scrn-01 lab-003-scrn-02 lab-003-scrn-03

Step 3 - Create a Route Table

Create a new route table with the Name tag private and with a default route to the NAT gateway created in step 2.

lab-003-scrn-04 lab-003-scrn-05 lab-003-scrn-06 lab-003-scrn-07 lab-003-scrn-08 lab-003-scrn-09 lab-003-scrn-10

Step 4 - Associate the Route Table to the Private Subnet

Associate the newly created route table to the private subnet.

lab-003-scrn-11 lab-003-scrn-12 lab-003-scrn-13 lab-003-scrn-14