How can I design an AWS auto-scaling group?

127    Asked by Deepabhawana in AWS , Asked on Mar 18, 2024

I am currently managing a web-based application that experiences varying levels of traffic throughout the day. How can I design an AWS auto-scaling group that can ensure that the application can handle high-traffic periods while minimizing costs during low-traffic periods? 

Answered by Crowny Hasegawa

 In the context of AWS, you can easily design an AWS auto-scaling group for your particular application with fluctuating traffic by using the following factors:-

Metrics and alarm

You can define cloud watch metrics and then set up alarms based on the metric to trigger scaling actions:-

Aws cloud watch put-metric-alarm –alarm-name CPUHighAlarm –metric-name CPU utilization –namespace AWS/EC2 –statistic Average –period 300 –threshold 80 –comparison-operator GreaterThanThreshold –evaluation-periods 2 –actions-enabled –alarm-actions

Scaling policies

You can create scaling policies to scale out and scale in based on the alarms.

Aws autoscaling put-scaling-policy –auto-scaling-group-name MyAutoScalingGroup –policy-name ScaleOutPolicy –scaling-adjustment 1 –adjustment-type ChangeInCapacity –cooldown 300

Aws autoscaling put-scaling-policy –auto-scaling-group-name MyAutoScalingGroup –policy-name ScaleInPolicy –scaling-adjustment -1 –adjustment-type ChangeInCapacity –cooldown 300

Instance types

You can try to choose an appropriate instance type that can handle the expected workload and scale accurately.

{
  “InstanceType”: “t3.micro”,
  “MinSize”: 1,
  “MaxSize”: 10,
  “DesiredCapacity”: 1,
  “AvailabilityZones”: [“us-east-1a”, “us-east-1b”],
  “LaunchConfigurationName”: “MyLaunchConfig”
}

Cooldown period

You can set a cooldown period to prevent the rapid scaling actions and stabilization of the environment.

Aws autoscaling update-auto-scaling-group –auto-scaling-group-name MyAutoScalingGroup –cooldown 300

Lifecycle hooks

You can optionally try to execute lifecycle hooks if you need to perform custom actions during instance launch or even termination.

Aws autoscaling put-lifecycle-hook –lifecycle-hook-name MyLifecycleHook –auto-scaling-group-name MyAutoScalingGroup –lifecycle-transition autoscaling:EC2_INSTANCE_TERMINATING –notification-target-arn --role-arn



Your Answer

Interviews

Parent Categories