Skip to content
Get Started for Free

Auto Scaling

Auto Scaling helps you maintain application availability and allows you to automatically add or remove EC2 instances according to the demand. You can use Auto Scaling to ensure that you are running your desired number of instances.

LocalStack allows you to use the Auto Scaling APIs locally to create and manage Auto Scaling groups locally. The supported APIs are available on our API Coverage section, which provides information on the extent of Auto Scaling’s integration with LocalStack.

This guide is designed for users new to Auto Scaling and assumes basic knowledge of the AWS CLI and our lstk aws command.

Start your LocalStack container using your preferred method. We will demonstrate how you can create a launch template, an Auto Scaling group, and attach an instance to the Auto Scaling group using the AWS CLI.

You can create a launch template that defines the launch configuration for the instances in the Auto Scaling group using the CreateLaunchTemplate API. Run the following command to create a launch template:

Terminal window
lstk aws ec2 create-launch-template \
--launch-template-name my-template-for-auto-scaling \
--version-description version1 \
--launch-template-data '{"ImageId":"ami-ff0fea8310f3","InstanceType":"t2.micro"}'
Output
{
"LaunchTemplate": {
"LaunchTemplateId": "lt-5ccdf1a84f178ba44",
"LaunchTemplateName": "my-template-for-auto-scaling",
"CreateTime": "2024-07-12T07:59:08+00:00",
"CreatedBy": "arn:aws:iam::000000000000:root",
"DefaultVersionNumber": 1,
"LatestVersionNumber": 1,
"Tags": []
}
}

Before creating an Auto Scaling group, you need to fetch the subnet ID. Run the following command to describe the subnets:

Terminal window
lstk aws ec2 describe-subnets --output text --query Subnets[0].SubnetId

Copy the subnet ID from the output and use it to create the Auto Scaling group. Run the following command to create an Auto Scaling group using the CreateAutoScalingGroup API:

Terminal window
lstk aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-template LaunchTemplateId=lt-5ccdf1a84f178ba44 \
--min-size 1 \
--max-size 5 \
--vpc-zone-identifier 'subnet-d4d16268'

You can describe the Auto Scaling group using the DescribeAutoScalingGroups API. Run the following command to describe the Auto Scaling group:

Terminal window
lstk aws autoscaling describe-auto-scaling-groups
Output
{
"AutoScalingGroups": [
{
"AutoScalingGroupName": "my-asg",
"AutoScalingGroupARN": "arn:aws:autoscaling:us-east-1:000000000000:autoScalingGroup:74b4ffac-4588-4a7c-86b1-9fa992f49c8e:autoScalingGroupName/my-asg",
"LaunchTemplate": {
"LaunchTemplateId": "lt-5ccdf1a84f178ba44",
"LaunchTemplateName": "my-template-for-auto-scaling"
},
"MinSize": 1,
"MaxSize": 5,
...
"Instances": [
{
"InstanceId": "i-fc01551d496fc363f",
"InstanceType": "t2.micro",
"AvailabilityZone": "us-east-1a",
...
}
],
...
"TerminationPolicies": [
"Default"
],
...
"CapacityRebalance": false
}
]
}

Attach an instance to the Auto Scaling group

Section titled “Attach an instance to the Auto Scaling group”

You can attach an instance to the Auto Scaling group using the AttachInstances API.

Before that, create an EC2 instance using the RunInstances API. Run the following command to create an EC2 instance locally:

Terminal window
lstk aws ec2 run-instances \
--image-id ami-ff0fea8310f3 --count 1

Fetch the instance ID from the output and use it to attach the instance to the Auto Scaling group. Run the following command to attach the instance to the Auto Scaling group:

Terminal window
lstk aws autoscaling attach-instances \
--instance-ids i-0d678c4ecf6018dde \
--auto-scaling-group-name my-asg

Replace i-0d678c4ecf6018dde with the instance ID that you fetched from the output.

LocalStack does not support the docker VM manager for EC2. It only works with the mock VM manager.

46 of 66 operations implemented

Available from the Base plan. Licensing details

Find an API

Search the full operation list, then sort the table to compare current support.

Loading operations…

Verified on Kubernetes
Loading operations…
Complete static API list All 66 operations and their current support status
OperationStatus
AttachInstancesImplemented
AttachLoadBalancerTargetGroupsImplemented
AttachLoadBalancersImplemented
AttachTrafficSourcesNot implemented
BatchDeleteScheduledActionImplemented
BatchPutScheduledUpdateGroupActionImplemented
CancelInstanceRefreshNot implemented
CompleteLifecycleActionNot implemented
CreateAutoScalingGroupImplemented
CreateLaunchConfigurationImplemented
CreateOrUpdateTagsImplemented
DeleteAutoScalingGroupImplemented
DeleteLaunchConfigurationImplemented
DeleteLifecycleHookImplemented
DeleteNotificationConfigurationNot implemented
DeletePolicyImplemented
DeleteScheduledActionImplemented
DeleteTagsImplemented
DeleteWarmPoolImplemented
DescribeAccountLimitsNot implemented
DescribeAdjustmentTypesNot implemented
DescribeAutoScalingGroupsImplemented
DescribeAutoScalingInstancesImplemented
DescribeAutoScalingNotificationTypesNot implemented
DescribeInstanceRefreshesNot implemented
DescribeLaunchConfigurationsImplemented
DescribeLifecycleHookTypesNot implemented
DescribeLifecycleHooksImplemented
DescribeLoadBalancerTargetGroupsImplemented
DescribeLoadBalancersImplemented
DescribeMetricCollectionTypesImplemented
DescribeNotificationConfigurationsNot implemented
DescribePoliciesImplemented
DescribeScalingActivitiesImplemented
DescribeScalingProcessTypesNot implemented
DescribeScheduledActionsImplemented
DescribeTagsImplemented
DescribeTerminationPolicyTypesNot implemented
DescribeTrafficSourcesNot implemented
DescribeWarmPoolImplemented
DetachInstancesImplemented
DetachLoadBalancerTargetGroupsImplemented
DetachLoadBalancersImplemented
DetachTrafficSourcesNot implemented
DisableMetricsCollectionImplemented
EnableMetricsCollectionImplemented
EnterStandbyImplemented
ExecutePolicyImplemented
ExitStandbyImplemented
GetPredictiveScalingForecastNot implemented
LaunchInstancesNot implemented
PutLifecycleHookImplemented
PutNotificationConfigurationNot implemented
PutScalingPolicyImplemented
PutScheduledUpdateGroupActionImplemented
PutWarmPoolImplemented
RecordLifecycleActionHeartbeatNot implemented
ResumeProcessesImplemented
RollbackInstanceRefreshNot implemented
SetDesiredCapacityImplemented
SetInstanceHealthImplemented
SetInstanceProtectionImplemented
StartInstanceRefreshNot implemented
SuspendProcessesImplemented
TerminateInstanceInAutoScalingGroupImplemented
UpdateAutoScalingGroupImplemented
Was this page helpful?