Load Balancer
Create a load balancer
Launch EC2 dashboard
Load Balancers -> Create Load Balancer
Select type (application, network, gateway, classic)
Give name
Choose internet-facing
Select vpc
Select subnet mappings
Create new security group
Set rule allowing traffic on desired port from anywhere (e.g. 80)
Create new target group
type: instances
set name
change port to target port (e.g. 3000)
Next -> Select instances for target group
Create
Select newly created target group
Enable session stickiness
This is useful to make sure that a user connecting to one load balancer stays logged in and doesn't logout by switching to a different load balancer. When enabled the user will consistently be sent to the same load balancer.
Target Group
Details -> Attributes -> Edit
Check Stickiness
Creating an auto-scaling group (ASG)
Auto-Scaling group
Create auto-scaling group
Create a new launch template
Select AMI
Select instance (free: t2.micro)
Select keypair (don't do this for production)
Select VPC
Select ec2 security group
Advanced details
Use user data section to start application on startup automatically
7. Select launch template
8. Select vpc & all subnets
9. Attach to an existing load balancer
10. Select target tracking policy, e.g. average network out and a value, then next until done.
Update launch template
Select launch template -> Actions -> Set default version -> Choose new version.
Access Load Balancer URL
Load Balancers
Select LB
Description -> DNS Name
Test Load Balancer
The command ab -n 100 -c 5 http://<loadbalancer-url>/
can be used to generate enough load to trigger the load balancer.
Last updated