Lab 13 1 Elastic Load Balancing Lab - nicolas-tullio/Tech-Journal GitHub Wiki
Deliverables
Instances in Targets tab
Load Balanced app in browser
AlarmHigh
Auto-scaled Instances
Steps
Create an AMI for Auto Scaling
Navigate to EC2 > Instances > Web Server 1
In the Actions menu, choose Image and templates > Create image
-
Image name:
WebServerAMI
-
Image description:
Lab AMI for Web Server
-
Create Image
Create a Load Balancer
In the left navigation pane, choose Target Groups
-
Choose Create target group
-
Choose a target type: Instances
-
Target group name, enter:
LabGroup
-
Select Lab VPC from the VPC drop-down menu
-
Choose Next
-
Review the settings and choose Create target group
Navigate to Load Balancers and choose Create load balancer
- Choose Application Load Balancer
Configure with the following settings
-
For Load balancer name, enter:
LabELB
-
For VPC, choose Lab VPC
-
Choose the first displayed Availability Zone, then select Public Subnet 1 from the Subnet drop down menu that displays beneath it.
-
Choose the second displayed Availability Zone, then select Public Subnet 2 from the Subnet drop down menu that displays beneath it.
In the Security groups section:
-
Choose the Security groups drop down menu and select Web Security Group
-
Deselect default security group
For the Listener HTTP:80 row, set the Default action to forward to LabGroup
Choose Create load balancer
Create a Launch Template and an Auto Scaling Group
In the left navigation pane, choose Launch Templates
Choose Create launch template
Configure the launch template settings and create it:
- Launch template name:
LabConfig
- Under Auto Scaling guidance, select Provide guidance to help me set up a template that I can use with EC2 Auto Scaling
- In the Application and OS Images (Amazon Machine Image) area, choose My AMIs.
- Amazon Machine Image (AMI): choose Web Server AMI
- Instance type: choose t2.micro
- Key pair name: choose vockey
- Firewall (security groups): choose Select existing security group
- Security groups: choose Web Security Group
- Scroll down to the Advanced details area and expand it.
- Scroll down to the Detailed CloudWatch monitoring setting. Select Enable
-
Note: This will allow Auto Scaling to react quickly to changing utilization.
-
Choose Create launch template
From the Actions menu, choose Create Auto Scaling group
Configure the details in Step 1 (Choose launch template or configuration):
-
Auto Scaling group name:
Lab Auto Scaling Group
-
Launch template: confirm that the LabConfig template you just created is selected.
-
Choose Next
Configure the details in Step 2 (Choose instance launch options):
-
VPC: choose
Lab VPC
-
Availability Zones and subnets: Choose Private Subnet 1 and then choose Private Subnet 2.
-
Choose Next
Configure the details in Step 3 (Configure advanced options):
-
Choose Attach to an existing load balancer
-
Existing load balancer target groups: select
LabGroup
. -
In the Additional settings pane:
-
Select Enable group metrics collection within CloudWatch
-
This will capture metrics at 1-minute intervals, which allows Auto Scaling to react quickly to changing usage patterns.
-
Choose Next
Configure the details in Step 4 (Configure group size and scaling policies - optional):
Under Group size, configure:
-
Desired capacity: 2
-
Minimum capacity: 2
-
Maximum capacity: 6
-
This will allow Auto Scaling to automatically add/remove instances, always keeping between 2 and 6 instances running.
Under Scaling policies, choose Target tracking scaling policy and configure:
-
Scaling policy name:
LabScalingPolicy
-
Metric type: Average CPU Utilization
-
Target value: 60
This tells Auto Scaling to maintain an average CPU utilization across all instances at 60%. Auto Scaling will automatically add or remove capacity as required to keep the metric at, or close to, the specified target value. It adjusts to fluctuations in the metric due to a fluctuating load pattern.
- Choose Next
Configure the details in Step 6 (Add tags - optional):
- Tags applied to the Auto Scaling group will be automatically propagated to the instances that are launched.
Choose Add tag and Configure the following:
-
Key:
Name
-
Value:
Lab Instance
-
Choose Next
Configure the details in Step 6 (Review):
-
Review the details of your Auto Scaling group
-
Choose Create Auto Scaling group
Verify that Load Balancing is Working
Navigate to EC2 > Instances
- You should see two new instances named Lab Instance. These were launched by Auto Scaling.
Navigate to EC2 > Target groups > LabGroup
Choose the Targets tab
- Two target instances named Lab Instance should be listed in the target group
Navigate to EC2 > Load balancers > LabELB
- In the Details pane, copy the DNS name of the load balancer, making sure to omit "(A Record)".
LabELB-1682420663.us-east-1.elb.amazonaws.com
Open a new web browser tab, paste the DNS Name you just copied, and press Enter.
- The application should appear in your browser. This indicates that the Load Balancer received the request, sent it to one of the EC2 instances, then passed back the result.
Test Auto Scaling
Navigate to CloudWatch > All Alarms
Two alarms will be displayed. These were created automatically by the Auto Scaling group. They will automatically keep the average CPU load close to 60% while also staying within the limitation of having two to six instances.
Choose the OK alarm, which has AlarmHigh in its name
The OK indicates that the alarm has not been triggered. It is the alarm for CPU Utilization > 60, which will add instances when average CPU is high. The chart should show very low levels of CPU at the moment.
Return to the browser tab with the web application
Choose Load Test beside the AWS logo
This will cause the application to generate high loads. The browser page will automatically refresh so that all instances in the Auto Scaling group will generate load. Do not close this tab.
Return to the CloudWatch console
- In less than 5 minutes, the
AlarmLow
alarm should change to OK and theAlarmHigh
alarm status should change to In alarm.