# Auto Scaling

Source: /aws/services/autoscaling/

## Introduction

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](#api-coverage), which provides information on the extent of Auto Scaling's integration with LocalStack.

## Getting started

This guide is designed for users new to Auto Scaling and assumes basic knowledge of the AWS CLI and our [`lstk aws`](/aws/developer-tools/running-localstack/lstk/cloud-and-iac-commands/#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.

### Create a launch template

You can create a launch template that defines the launch configuration for the instances in the Auto Scaling group using the [`CreateLaunchTemplate`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateLaunchTemplate.html) API.
Run the following command to create a launch template:

```bash
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"}'
```

```bash title="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": []
    }
}
```

### Create an Auto Scaling group

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

```bash
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`](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_CreateAutoScalingGroup.html) API:

```bash
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'
```

### Describe the Auto Scaling group

You can describe the Auto Scaling group using the [`DescribeAutoScalingGroups`](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_DescribeAutoScalingGroups.html) API.
Run the following command to describe the Auto Scaling group:

```bash
lstk aws autoscaling describe-auto-scaling-groups
```

```bash title="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

You can attach an instance to the Auto Scaling group using the [`AttachInstances`](https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_AttachInstances.html) API.

Before that, create an EC2 instance using the [`RunInstances`](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_RunInstances.html) API.
Run the following command to create an EC2 instance locally:

```bash
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:

```bash
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.

## Current Limitations

LocalStack does not support the `docker` [VM manager for EC2](/aws/services/ec2/#vm-managers).
It only works with the `mock` VM manager.

## API Coverage


### Auto Scaling API coverage

Source service: `autoscaling`. 46 of 66 tracked operations are implemented.

Service documentation: /aws/services/autoscaling/
License availability: available starting with the Base plan. See /aws/licensing/ for current plan details.

| Operation | Status |
| --- | --- |
| AttachInstances | Implemented |
| AttachLoadBalancerTargetGroups | Implemented |
| AttachLoadBalancers | Implemented |
| AttachTrafficSources | Not implemented |
| BatchDeleteScheduledAction | Implemented |
| BatchPutScheduledUpdateGroupAction | Implemented |
| CancelInstanceRefresh | Not implemented |
| CompleteLifecycleAction | Not implemented |
| CreateAutoScalingGroup | Implemented |
| CreateLaunchConfiguration | Implemented |
| CreateOrUpdateTags | Implemented |
| DeleteAutoScalingGroup | Implemented |
| DeleteLaunchConfiguration | Implemented |
| DeleteLifecycleHook | Implemented |
| DeleteNotificationConfiguration | Not implemented |
| DeletePolicy | Implemented |
| DeleteScheduledAction | Implemented |
| DeleteTags | Implemented |
| DeleteWarmPool | Implemented |
| DescribeAccountLimits | Not implemented |
| DescribeAdjustmentTypes | Not implemented |
| DescribeAutoScalingGroups | Implemented |
| DescribeAutoScalingInstances | Implemented |
| DescribeAutoScalingNotificationTypes | Not implemented |
| DescribeInstanceRefreshes | Not implemented |
| DescribeLaunchConfigurations | Implemented |
| DescribeLifecycleHookTypes | Not implemented |
| DescribeLifecycleHooks | Implemented |
| DescribeLoadBalancerTargetGroups | Implemented |
| DescribeLoadBalancers | Implemented |
| DescribeMetricCollectionTypes | Implemented |
| DescribeNotificationConfigurations | Not implemented |
| DescribePolicies | Implemented |
| DescribeScalingActivities | Implemented |
| DescribeScalingProcessTypes | Not implemented |
| DescribeScheduledActions | Implemented |
| DescribeTags | Implemented |
| DescribeTerminationPolicyTypes | Not implemented |
| DescribeTrafficSources | Not implemented |
| DescribeWarmPool | Implemented |
| DetachInstances | Implemented |
| DetachLoadBalancerTargetGroups | Implemented |
| DetachLoadBalancers | Implemented |
| DetachTrafficSources | Not implemented |
| DisableMetricsCollection | Implemented |
| EnableMetricsCollection | Implemented |
| EnterStandby | Implemented |
| ExecutePolicy | Implemented |
| ExitStandby | Implemented |
| GetPredictiveScalingForecast | Not implemented |
| LaunchInstances | Not implemented |
| PutLifecycleHook | Implemented |
| PutNotificationConfiguration | Not implemented |
| PutScalingPolicy | Implemented |
| PutScheduledUpdateGroupAction | Implemented |
| PutWarmPool | Implemented |
| RecordLifecycleActionHeartbeat | Not implemented |
| ResumeProcesses | Implemented |
| RollbackInstanceRefresh | Not implemented |
| SetDesiredCapacity | Implemented |
| SetInstanceHealth | Implemented |
| SetInstanceProtection | Implemented |
| StartInstanceRefresh | Not implemented |
| SuspendProcesses | Implemented |
| TerminateInstanceInAutoScalingGroup | Implemented |
| UpdateAutoScalingGroup | Implemented |
