DEV Community

Abdullah Al Reza
Abdullah Al Reza

Posted on

EC2 Auto Scaling and how it works.

Problem: Your web application uses EC2, and the web traffic is periodic, unpredictable, or continuously changing. If you have fixed EC2, then during the pick hour, the fixed VMs are unable to handle the traffic, and conversely, at normal hours, the VMs will be unutilized.

Solution: Using AWS Auto Scaling, we can easily mitigate this issue. AWS Auto Scaling continually monitors your applications to make sure that they are operating at your desired performance levels. When demand spikes, AWS Auto Scaling automatically increases the capacity of constrained resources so you can maintain a high quality of service. It allows you to only pay for the resources you actually need. So you can optimize the cost.
How it works:
Suppose you have a website www.reza.com and you want to run this site by using aws auto scaling feature.

Services needed for this requirement:

  1. Route53
  2. Application Load Balancer
  3. Target group
  4. Auto Scaling group
  5. EC2

Step 1:
Deploy your website in ec2. See the status of your instance is running and functioning. Create a image from the instance, so that you can use this image for creating the launch template.

Step 2:
Create target group and registered the instance.
Step 3:
Create auto scaling group

  • Provide a name to identify the group
  • Create launch template. Provide template name. Select the image from AMI (previously created from instance), use same configuration for the others filed (network, key, security group) from your ec2.
  • Set VPC, Availability Zones and subnets
  • After creating auto scaling group, open the auto scaling group, go the auto scaling tab and set the Dynamic scaling policies by using EC2 CPU utilization metric.

*Step 4: *
Create internet-facing Application Load Balancer, Set network mapping and Security groups from EC2 configuration.
Listeners and routing- protocol http, port 80 redirect to protocol https, port 443

Image description

Add another listener
protocol https, port 443 forward to created target group

Image description

Finally, from the route53, you just point your website to the load balancer.

Top comments (0)