EC2 instance Autoscaling

In this Lab you will get the idea of the following:
Created an Amazon EC2 launch template
Created an Amazon EC2 Auto Scaling launch configuration
Configured scaling policies and created auto Scaling group to scale in and scale out the number of servers based on variable load
You need to first create these for this lab:

VPC with subnet 10.0.0.0/16
For Availability Zone 1
public subnet: 10.0.0.0/24
private subnet: 10.0.1.0/24
For Availability Zone 2
public subnet: 10.0.2.0/24
private subnet: 10.0.3.0/24
Security Group
- Inbound rule: HTTP and SSH
[ Visit my previous blogs for Creating VPC and Security group if you had problem ]
Let's begin:
- In EC2 -> Load Balancing session select Load Balancers and Create load balancer Select Application load balancer
Basic configuration
Load balancer name:
WebELBSelect VPC:
myVPCMappings:
Select at least two AG so select both public subnets of different AG
Security groups
- Security group: Select that you created to access HTTP
Listener and routing
Protocol: HTTP Port: 80
Create target group as:
Target group name:
web-appVPC:
myVPCNext
Register the targets session leave it as default and
Create target group
-Go back to the load balancer tab, refresh, and select the target group that you created
- Creating a launch template
In the EC2 left bar there is an instances section in which Launch Templates also select and create launch templates as:
Launch template name:
webtempTemplate version description:
For autoscaling useSelect
Provide guidance to help me set up a template that I can use with EC2 Auto ScalingApplication and OS Images: select
My AMIsand leave the default optionInstance type:
t3.microor other free tiers if exitsKey pait(login)-> Key pair name:
don't include in the launch templateNetwork Settings-> Subnet:
Don't include in launch templateFirewall(security group): Select the existing security group and select that you created for HTTP accessLeave all defaults and Create launch template
- Creating an Auto Scaling group
Choose the Launch template that we created and From
Actiondropdown select Create Auto Scaling groupName ->
Auto Scaling group name:
Web Auto Scaling GroupAll Default and
Next
Network ->
VPC:
myVPCAvailability Zones and subnets:
Select both private subnetsChoose
Next
Load balancing ->
Select Attach to an existing load balancer
- Existing load balancer target groups: Select
web-appthat you created
- Existing load balancer target groups: Select
Health checks:- Select
Turn on Elastic Load Balancing health checksChoose
Next
Configure group Size and scaling policies - optional
-> Group size - optional
Desired capacity:
2Minimum capacity:
2Maximum capacity:
4
-> Scaling policies - optional
Select Target tracking scaling policy
Metric type: choose
Average CPU utilizationTarget value:
50Choose
Next
Add notifications - optional
- Choose
Next
- Choose
Add tags - optional
- Choose Add tag Key: Name Value-optional:
WebApp
- Choose Add tag Key: Name Value-optional:
Review and Create Auto Scaling group
- Verify autoscaling
Select instances and you see there are 2
WebAppnamed instances are automatically createdSelect Target Groups and select that you created above and observe health status -> healthy
- Test auto-scaling configuration
- When the Load of CPU utilization reaches 50%+ after a few minutes you should see your auto-scaling group add a new instance. This occurs because Amazon CloudWatch detected that the average CPU utilization of your Auto Scaling group exceeds 50% and your scale-up policy has been invoked in response. The maximum of 4 instances of name WebApp created according to policy. You can add more if needed.
