0
0
AWScloud~5 mins

Why auto scaling matters in AWS - Why It Works

Choose your learning style9 modes available
Introduction
Auto scaling helps your app handle more users by adding more servers when needed and saves money by removing them when not needed. It keeps your app fast and available without you doing it manually.
When your website gets more visitors during the day and fewer at night
When you run an online store that has big sales events with many buyers
When you want to avoid your app crashing because too many people use it at once
When you want to save money by not paying for extra servers when they are not needed
When you want your app to recover quickly if a server stops working
Config File - autoscaling-group.json
autoscaling-group.json
{
  "AutoScalingGroupName": "example-auto-scaling-group",
  "LaunchConfigurationName": "example-launch-config",
  "MinSize": 1,
  "MaxSize": 3,
  "DesiredCapacity": 1,
  "AvailabilityZones": ["us-east-1a", "us-east-1b"],
  "Tags": [
    {
      "Key": "Name",
      "Value": "example-instance",
      "PropagateAtLaunch": true
    }
  ]
}

This JSON file defines an Auto Scaling group in AWS.

  • AutoScalingGroupName: The name of the group managing your servers.
  • LaunchConfigurationName: The settings for new servers, like which image to use.
  • MinSize: The smallest number of servers to keep running.
  • MaxSize: The largest number of servers allowed.
  • DesiredCapacity: How many servers to start with.
  • AvailabilityZones: The data centers where servers will run.
  • Tags: Labels to identify your servers.
Commands
This command creates the auto scaling group using the settings from the JSON file. It sets up the rules for adding or removing servers automatically.
Terminal
aws autoscaling create-auto-scaling-group --cli-input-json file://autoscaling-group.json
Expected OutputExpected
No output (command runs silently)
--cli-input-json - Specifies the JSON file with the auto scaling group configuration
This command checks the details of the auto scaling group to confirm it was created and see its current status.
Terminal
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names example-auto-scaling-group
Expected OutputExpected
{ "AutoScalingGroups": [ { "AutoScalingGroupName": "example-auto-scaling-group", "MinSize": 1, "MaxSize": 3, "DesiredCapacity": 1, "AvailabilityZones": [ "us-east-1a", "us-east-1b" ], "Instances": [] } ] }
--auto-scaling-group-names - Specifies which auto scaling group to describe
This command changes the desired number of servers to 2, simulating an increase in traffic where more servers are needed.
Terminal
aws autoscaling update-auto-scaling-group --auto-scaling-group-name example-auto-scaling-group --desired-capacity 2
Expected OutputExpected
No output (command runs silently)
--desired-capacity - Sets the target number of servers running
This command lists the servers currently managed by auto scaling, showing how many are running after the update.
Terminal
aws autoscaling describe-auto-scaling-instances
Expected OutputExpected
{ "AutoScalingInstances": [ { "InstanceId": "i-0123456789abcdef0", "AutoScalingGroupName": "example-auto-scaling-group", "AvailabilityZone": "us-east-1a", "LifecycleState": "InService", "HealthStatus": "Healthy" }, { "InstanceId": "i-0fedcba9876543210", "AutoScalingGroupName": "example-auto-scaling-group", "AvailabilityZone": "us-east-1b", "LifecycleState": "InService", "HealthStatus": "Healthy" } ] }
Key Concept

If you remember nothing else from this pattern, remember: auto scaling automatically adjusts the number of servers to keep your app fast and cost-effective.

Common Mistakes
Setting MinSize and MaxSize to the same number
This stops auto scaling from adding or removing servers, defeating its purpose.
Set MinSize lower than MaxSize to allow scaling up and down.
Not specifying Availability Zones
Servers may all run in one data center, risking downtime if that zone fails.
Specify multiple Availability Zones for better reliability.
Forgetting to create a launch configuration before the auto scaling group
Auto scaling group needs launch configuration to know how to start new servers.
Create a launch configuration first and reference it in the auto scaling group.
Summary
Create an auto scaling group with a JSON file defining min, max, and desired server counts.
Use AWS CLI commands to create, check, and update the auto scaling group.
Auto scaling helps keep your app responsive and saves money by adjusting servers automatically.