AWS Application Load Balancer with Auto Scaling group
Look more detail theory of Part -1
Type of Policies:
Script for EC-2 User data
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1> This Message from: $(hostname -i)</h1>" >/var/www/html/index.html
- Go to EC2 and create two security groups:
One SG for ALB
One for Auto Scaling -SG
Once done the SG topics, Move to Auto Scaling groups in Ec2
Launch a template for ASG
if you don't have a template as a pre-requisite, create one.
Choose ‘Amazon-Linux’; if you want to choose any other, you can..!
Keep all those things as you know. Use user data to feed the script.
Then create a launch template.
Then Back to Auto scaling — Refresh and select the Template that you created,
Choose an Attach Load Balancer and create. Use Application LB
Use AZ’s min 2 , so add subnets.
Create a Target Group for redirect to the Ec2
choose all as default and create a Auto scaling group
ASG created and ALB is created
Instance created and ALB is in Active state. Copy the DNS and paste in Browser and see
Apply Dynamic Scaling Policy to scale ec2 instance.
If create a policy, automatically the Cloud Watch alarm is created.
Then back to the Ec2 instance, you find only one instance will running state.
Feed some manual script to raise the load on the server. Then only the CPU utilization will increase, and the alarm can trigger as we expected.
Monitor the instance, then catch up the CPU grows in the server
If the CPU load spikes the limit, the scaling will happen automatically.
Output Result :
Hope it helps..!
Thank you for reading so far! Before you go:
- 👏 Clap for the story if it helped :)
- 📰 View more content from me https://medium.com/@clouddevsecops